Results 1 to 5 of 5

Thread: error QIODevice::read called with maxSize <0

  1. #1
    Join Date
    Nov 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default error QIODevice::read called with maxSize <0

    Qextserialport error QIODevice::read called with maxSize <0
    I am using qextserialport to get some data from serial port , everything is working but i am getting

    QIODevice::read called with maxSize <0
    QIODevice::read called with maxSize <0[/SIZE]

    again and again
    my files are as



    main.cpp is
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include"receiveport.h"
    3. //#include<qextserialport.h>
    4. #include<QDebug>
    5. int main(int argc, char *argv[])
    6. {
    7. QCoreApplication a(argc, argv);
    8. QextSerialPort *port =new QextSerialPort ;
    9. port->setBaudRate(BAUD19200);
    10. port->setDataBits(DATA_8);
    11. port->setFlowControl(FLOW_OFF);
    12. port->setStopBits(STOP_1);
    13. port->setParity(PAR_NONE);
    14. if(port->open(QIODevice::ReadWrite))
    15. qDebug()<<"Successfully opened the port";
    16. else
    17. qDebug()<<"Failed";
    18. ReceivePort *myport =new ReceivePort(port);
    19. myport->startReceiving();
    20. myport->start();
    21. return a.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 



    receiveport.h is
    Qt Code:
    1. #ifndef RECEIVEPORT_H
    2. #define RECEIVEPORT_H
    3. #include "files/qextserialport.h"
    4. #include <QMutex>
    5. #include<QDebug>
    6. #include<QThread>
    7. class ReceivePort :public QThread
    8. {
    9. Q_OBJECT
    10. private:
    11.  
    12. bool stopped ;
    13. QextSerialPort *receiveport ;
    14. QMutex receivemutex ;
    15.  
    16. public:
    17. ReceivePort(QextSerialPort *port);
    18. void stopReceiving();
    19. void startReceiving();
    20.  
    21. protected:
    22. void run();
    23. signals:
    24. void BytesReceived_signal(const QByteArray &data);
    25. };
    26.  
    27. #endif // RECEIVEPORT_H
    To copy to clipboard, switch view to plain text mode 





    receiveport.cpp is
    Qt Code:
    1. #include "receiveport.h"
    2.  
    3. ReceivePort::ReceivePort(QextSerialPort *port)
    4. {
    5. receiveport = port ;
    6. stopped = false ; //initially the receiving is disabled
    7. }
    8. void ReceivePort::run()
    9. {
    10. int numbytes = 0 ;
    11. char data[1024] ;
    12. QByteArray receivedData ;
    13. while(1)
    14. {
    15. if(stopped)
    16. {
    17. stopped =false ;
    18. break;
    19. }
    20. numbytes = receiveport->bytesAvailable();
    21. if(numbytes)
    22. {
    23. receivemutex.lock();
    24. receiveport->read(data,numbytes);
    25. receivedData =data ;
    26. receivemutex.unlock();
    27. emit BytesReceived_signal(receivedData);
    28. qDebug()<<data;
    29. }
    30. }
    31.  
    32. }
    33. void ReceivePort::startReceiving()
    34. {
    35. stopped =false ;
    36. }
    37. void ReceivePort::stopReceiving()
    38. {
    39. stopped = true ;
    40. }
    To copy to clipboard, switch view to plain text mode 



    Please sort out the problem and tell me how can i avoid it.
    Last edited by wysota; 20th January 2012 at 16:17. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: error QIODevice::read called with maxSize <0

    What is the value of numbytes in line #20 of receiveport.cpp?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error QIODevice::read called with maxSize <0

    if there is some data availabe at serial port it would be positive integer otherwise it would be zero

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error QIODevice::read called with maxSize <0

    My private opinion : this is bad habit in a situation such as this.
    Qt Code:
    1. if(numbytes)
    To copy to clipboard, switch view to plain text mode 
    Better is :
    Qt Code:
    1. if(numbytes > 0)
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: error QIODevice::read called with maxSize <0

    Quote Originally Posted by sanjuchopracool View Post
    if there is some data availabe at serial port it would be positive integer otherwise it would be zero
    I'm asking what is and not what would be. In my opinion it is -1 or some other negative value.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QIODevice read() problem (reads more than maxSize)
    By m15ch4 in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2011, 11:09
  2. Does bytesAvailable() decrease when read() is called?
    By ShaChris23 in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2010, 21:16
  3. Replies: 1
    Last Post: 16th June 2009, 09:09
  4. Using QIODevice to read a GPS filenode?
    By hickscorp in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 3rd December 2007, 22:32
  5. QIODevice read()
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 00:29

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
  •  
Qt is a trademark of The Qt Company.