quickNitin
14th June 2006, 06:25
hi
i am trying to read from a fifo and checking availability of data on fifo using QIODevice::bytesAvailable() which as per doc returns no of bytes availble for reading.
But to me it is always returns 0.
Aim of following code is to see whether something is there for reading in file if yes read it and append to textlabel.
#include"MyDialog.h"
#include<iostream>
#include<QTimer>
#include<QString>
#include<QFile>
using namespace std;
MyDialog::MyDialog()
{
setupUi(this);
connect(this,SIGNAL(yesAvailable()),this,SLOT(read DataHere()));
connect(checkBox,SIGNAL(clicked()),this,SLOT(openF ile()));
connect(this,SIGNAL(dataFound()),this,SLOT(receive OnRead()));
flag=false;
}
MyDialog::~MyDialog()
{
}
void MyDialog::openFile()
{ if(flag==false)
{
flag=true;
fifoFile.setFileName("/home/prince/mydev01");
if(!fifoFile.open(QIODevice::ReadOnly))
cout<<"Error in opening the fifofile"<<endl;
else
{ cout<<"File opened\n";
connect(&fifoFile,SIGNAL(readyRead()),this,SLOT(readDataHer e()));
QTimer *t=new QTimer(this);
connect(t,SIGNAL(timeout()),this,SLOT(checkingAvai lability()));
t->start(1001);
}
}
}
void MyDialog::checkingAvailability()
{ long x;
if(fifoFile.canReadLine())
cout<<" \n YA can read line";
else
cout<<" \n Can't read line:";
x=fifoFile.bytesAvailable();
cout<<"\t No of bytes available"<<x<<"\t";
if(x>0)
{
emit yesAvailable();
}
}
void MyDialog::receiveOnRead()
{
QString sx;
sx.setNum(x);
QString sy;
sy.setNum(y);
label->setText(sx+QString(" ") +sy);
cout<<"\n From dialog "<<x<<" "<<y<<endl;
}
void MyDialog::readDataHere()
{
if(fifoFile.canReadLine())
cout<<" \n YA can read line";
QByteArray temp=fifoFile.read(2);
bool conversionErrorFlag;
x=temp.toInt(&conversionErrorFlag);
temp=fifoFile.read(2);
cout<<"\t "<<x;
y=temp.toInt(&conversionErrorFlag);
emit dataFound();
}
quick nitin
i am trying to read from a fifo and checking availability of data on fifo using QIODevice::bytesAvailable() which as per doc returns no of bytes availble for reading.
But to me it is always returns 0.
Aim of following code is to see whether something is there for reading in file if yes read it and append to textlabel.
#include"MyDialog.h"
#include<iostream>
#include<QTimer>
#include<QString>
#include<QFile>
using namespace std;
MyDialog::MyDialog()
{
setupUi(this);
connect(this,SIGNAL(yesAvailable()),this,SLOT(read DataHere()));
connect(checkBox,SIGNAL(clicked()),this,SLOT(openF ile()));
connect(this,SIGNAL(dataFound()),this,SLOT(receive OnRead()));
flag=false;
}
MyDialog::~MyDialog()
{
}
void MyDialog::openFile()
{ if(flag==false)
{
flag=true;
fifoFile.setFileName("/home/prince/mydev01");
if(!fifoFile.open(QIODevice::ReadOnly))
cout<<"Error in opening the fifofile"<<endl;
else
{ cout<<"File opened\n";
connect(&fifoFile,SIGNAL(readyRead()),this,SLOT(readDataHer e()));
QTimer *t=new QTimer(this);
connect(t,SIGNAL(timeout()),this,SLOT(checkingAvai lability()));
t->start(1001);
}
}
}
void MyDialog::checkingAvailability()
{ long x;
if(fifoFile.canReadLine())
cout<<" \n YA can read line";
else
cout<<" \n Can't read line:";
x=fifoFile.bytesAvailable();
cout<<"\t No of bytes available"<<x<<"\t";
if(x>0)
{
emit yesAvailable();
}
}
void MyDialog::receiveOnRead()
{
QString sx;
sx.setNum(x);
QString sy;
sy.setNum(y);
label->setText(sx+QString(" ") +sy);
cout<<"\n From dialog "<<x<<" "<<y<<endl;
}
void MyDialog::readDataHere()
{
if(fifoFile.canReadLine())
cout<<" \n YA can read line";
QByteArray temp=fifoFile.read(2);
bool conversionErrorFlag;
x=temp.toInt(&conversionErrorFlag);
temp=fifoFile.read(2);
cout<<"\t "<<x;
y=temp.toInt(&conversionErrorFlag);
emit dataFound();
}
quick nitin