QSocketNotifier does not seem to read the complete stream
===

I have a QSocketNotifier which reads data from the serial port (from the file /dev/ttyUSB0). QSocketNotifier seems to chop the string, though...
I've taken some code from CuteCom (*apt-get source cutecom* in Debian-like systems) and I tried to implement it in a terminal-only program. So, here it is, so far:

**main.cpp:**

    #include <QtCore/QCoreApplication>
    #include <QSocketNotifier>
    #include <QTimer>
    #include <QDebug>
    
    #include <sys/termios.h>
    #include <stdio.h>
    #include <fcntl.h>
    #include <iostream>
    
    using namespace std;
    
    QSocketNotifier *m_notifier;
    QString output_buffer="";
    int m_fd;
    char m_buf[4096];
    
    class Timer : public QTimer {
      Q_OBJECT
    public:
      explicit Timer(QObject *parent = 0) : QTimer(parent) {
    
      }
    public slots:
        void readData(int fd){
            if (fd!=m_fd)
               return;
    
            int bytesRead=::read(m_fd, m_buf, 4096);
    
            if (bytesRead<0)
            {
               cerr << "read result: " << bytesRead << endl;
               return;
            }
            // if the device "disappeared", e.g. from USB, we get a read event for 0 bytes
            else if (bytesRead==0)
            {
               disconnectTTY();
               return;
            }
    
            const char* c=m_buf;
            qDebug() << "THEY CAME " << bytesRead << " bytes!";
            QString text="";
            for (int i=0; i<bytesRead; i++)
            {
                // also print a newline for \r, and print only one newline for \r\n
                if ((isprint(*c)) || (*c=='\n') || (*c=='\r'))
                {
                    text+=(*c);
                }
                else
                {
                    char buf[64];
                    unsigned int b=*c;
                    snprintf(buf, 16, "\\0x%02x", b & 0xff);
                    text+=buf;
                }
             c++;
            }
            addOutput(text);
        }
        void addOutput(QString text){
            output_buffer+=text;
            this->setSingleShot(true);
            this->start(100);
        }
        void process_input(){
            //this function processes the input strings.
            cout << QString(output_buffer).toLocal8Bit().data();
            output_buffer.clear();
        }
        void create_avg(){
            cout << "I will create the average in the future!\n";
        }
        void disconnectTTY(){
            delete m_notifier;
            m_notifier=0;
        }
        void connect_normal_timer()
        {
            connect(this, SIGNAL(timeout()), this, SLOT(process_input()));
        }
        void connect_avg_maker_timer()
        {
            connect(this ,SIGNAL(timeout()), this, SLOT(create_avg()));
        }
        void disconnect_from_slot()
        {
            disconnect(this, 0, this, 0);
        }
        void create_notifier(){
            m_notifier=new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
            connect(m_notifier, SIGNAL(activated(int)), this, SLOT(readData(int)));
        }
    };
    
    void open_device(QString device){
        m_fd=open(device.toLatin1(), O_RDONLY | O_NDELAY | O_NONBLOCK);//O_NDELAY);
        if(m_fd<0){
            cerr << QString("Cannot open device '"+device+"'\n").toLocal8Bit().data();
            exit(1);
        }
       tcflush(m_fd, TCIOFLUSH);
    }
    
    Timer timer;
    Timer avg_maker;
    
    #include "main.moc"
    
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        /*
          SETTING UP TIMERS
        */
    
        timer.connect_normal_timer();
        avg_maker.connect_avg_maker_timer();
    
        /*
          OPENING DEVICE
        */
    
        open_device("/dev/ttyUSB0");
    
        /*
          CREATE SOCKET READER
        */
        timer.create_notifier();
    
        avg_maker.start(3000);
        return a.exec();
    }

So, I setup 2 timers, I open /dev/ttyUSB0 for reading only and then I connect my QSocket notifier. The problem is that I only get chopped (in the middle) strings and never an actual big string! I don't know what may cause the problem, but Cutecom works well while the above program does not!

While I don't know what the actual problem is, I know that none of my checks actual cause this program (I have not applied any string filtering) and that QSocketNotifier in fact sends only some first and some last part of the string (never the whole string).

I know this one is hard, but, if anyone can help... Thanks!