Results 1 to 7 of 7

Thread: QIODevice::bytesAvailable() always returning 0

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QIODevice::bytesAvailable() always returning 0

    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.

    Qt Code:
    1. #include"MyDialog.h"
    2. #include<iostream>
    3. #include<QTimer>
    4. #include<QString>
    5. #include<QFile>
    6. using namespace std;
    7.  
    8. MyDialog::MyDialog()
    9. {
    10. setupUi(this);
    11. connect(this,SIGNAL(yesAvailable()),this,SLOT(readDataHere()));
    12. connect(checkBox,SIGNAL(clicked()),this,SLOT(openFile()));
    13. connect(this,SIGNAL(dataFound()),this,SLOT(receiveOnRead()));
    14. flag=false;
    15.  
    16. }
    17.  
    18. MyDialog::~MyDialog()
    19. {
    20.  
    21. }
    22. void MyDialog::openFile()
    23. { if(flag==false)
    24. {
    25. flag=true;
    26. fifoFile.setFileName("/home/prince/mydev01");
    27. if(!fifoFile.open(QIODevice::ReadOnly))
    28. cout<<"Error in opening the fifofile"<<endl;
    29. else
    30. { cout<<"File opened\n";
    31. connect(&fifoFile,SIGNAL(readyRead()),this,SLOT(readDataHere()));
    32. QTimer *t=new QTimer(this);
    33. connect(t,SIGNAL(timeout()),this,SLOT(checkingAvailability()));
    34. t->start(1001);
    35. }
    36. }
    37. }
    38. void MyDialog::checkingAvailability()
    39. { long x;
    40. if(fifoFile.canReadLine())
    41. cout<<" \n YA can read line";
    42. else
    43. cout<<" \n Can't read line:";
    44. x=fifoFile.bytesAvailable();
    45. cout<<"\t No of bytes available"<<x<<"\t";
    46. if(x>0)
    47. {
    48.  
    49. emit yesAvailable();
    50. }
    51. }
    52.  
    53. void MyDialog::receiveOnRead()
    54. {
    55.  
    56. QString sx;
    57. sx.setNum(x);
    58. QString sy;
    59. sy.setNum(y);
    60. label->setText(sx+QString(" ") +sy);
    61. cout<<"\n From dialog "<<x<<" "<<y<<endl;
    62. }
    63.  
    64. void MyDialog::readDataHere()
    65. {
    66. if(fifoFile.canReadLine())
    67. cout<<" \n YA can read line";
    68. QByteArray temp=fifoFile.read(2);
    69. bool conversionErrorFlag;
    70. x=temp.toInt(&conversionErrorFlag);
    71. temp=fifoFile.read(2);
    72. cout<<"\t "<<x;
    73. y=temp.toInt(&conversionErrorFlag);
    74. emit dataFound();
    75. }
    To copy to clipboard, switch view to plain text mode 

    quick nitin
    Last edited by quickNitin; 14th June 2006 at 07:46. Reason: code changed

Similar Threads

  1. Replies: 12
    Last Post: 14th June 2006, 09:24
  2. [DevQt] New versions, feature requests and bug reports
    By fullmetalcoder in forum Qt-based Software
    Replies: 103
    Last Post: 15th May 2006, 09:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.