Hello,
I have managed to open and read /dev/rfcomm0 using a simple C app i worte, using fopen, fread and fwrite, on Ubuntu 10.04.
now i want to do that in Qt.
I managed to open the file (doesnt fail in first 2 checks), but returns 0 on number of bytes available for read. and if i skip bytesAvailable() and just read the device it gets stuck there infinitely. hints plz in opening reading device files using QT?
here is the code. i tried that as well on N900 and same. Thanks in advance.
#include <QApplication>
#include <QFile>
#include <QDebug>
#include <QLabel>
#include <QIODevice>
QIODevice *fd;
//i tried QFile as well but no success
int main(int argc, char *argv[])
{
qint64 i;
fd
= new QFile("/dev/rfcomm0");
hello.resize(300, 100);
hello.show();
{
qDebug() << "Failed opening";
return 0;
}
if( !fd->isReadable() )
{
qDebug() << "Not Readable";
return 0;
}
qDebug() << "Please Wait";
sleep(1);
i = fd->bytesAvailable();
qDebug() << "i:" << i;
if(i == 0)
{
return 0;
}
ba = fd->read(1);
qDebug() << "DATA:" << ba;
fd->close();
return app.exec();
}
#include <QApplication>
#include <QFile>
#include <QDebug>
#include <QLabel>
#include <QIODevice>
QIODevice *fd; //i tried QFile as well but no success
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel hello("Hello world!");
qint64 i;
QByteArray ba;
fd = new QFile("/dev/rfcomm0");
hello.resize(300, 100);
hello.show();
if( !fd->open(QIODevice::ReadWrite) )
{
qDebug() << "Failed opening";
return 0;
}
if( !fd->isReadable() )
{
qDebug() << "Not Readable";
return 0;
}
qDebug() << "Please Wait";
sleep(1);
i = fd->bytesAvailable();
qDebug() << "i:" << i;
if(i == 0)
{
return 0;
}
ba = fd->read(1);
qDebug() << "DATA:" << ba;
fd->close();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks