Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QSerialPort blocked by GUI
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QSerialPort blocked by GUI

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 4.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M4chin3
    wrote on last edited by
    #1

    Hi,

    i'm developing a GUI application with a serial communication.
    The program has to send data to a device connected to the serial port every 500ms. (keepalive)
    So i created a new class with a QTimer inside which calls a slot when its timeout() signal occurs.
    I move this class to a new thread (moveToThread()) to have it decoupled from the GUI thread.
    In the slot that is called from the QTimer i'm sending my data. This works as designed as long as i don't move my GUI window.

    As soon as i click and hold the GUI window to move it the communication stops for the time i'm holding the mouse button. Like this the user could "move" the window for a very long time and disturb the communication.

    What am I doing wrong? Am I using the QThread in a wrong way?
    Thank you.

    header:
    @
    class SerialWorker : public QObject {
    Q_OBJECT

    public:
    SerialWorker(QObject * ObjectToTriggerOnTimer, qint16 CallTime);
    void SendString(void);
    QSerialPort SerialPort;
    public slots:
    void OnReceiveTimer(void);
    signals:
    void finished();
    private:
    QTimer * ReceiveTimer;

    };
    @

    Source
    @

    SerialWorker::SerialWorker() {
    this->ReceiveTimer = new QTimer(this);
    connect(ReceiveTimer, SIGNAL(timeout()), this, SLOT(OnReceiveTimer()));

    ReceiveTimer->setTimerType(Qt::PreciseTimer);
    ReceiveTimer->start(500);
    

    }

    void SerialWorker::SendString(void){
    char data[]={1,2,3};
    SerialPort.write(data,3);
    }
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      djszapi
      wrote on last edited by
      #2

      First of all: http://sscce.org/

      Are you sure it is QtSerialPort specific? Have you tried with general QIODevice like writing a file periodically, etc, or even dropping QIODevice, but do something else?

      Also, does it happen on a particular OS, or it is a cross-platform behavior you see? Do you use Qt 4 or 5, etc? Much more information is needed, sorry. :-)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        M4chin3
        wrote on last edited by
        #3

        Sorry, i totally forgot about that:
        I'm using Qt 5.1.1 on Windows 7 Prof 64bit

        I don't know if it is QSerialPort specific. I have not tried it yet with a QIODevice because my first thought was i'm doing something wrong with the QThread.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          djszapi
          wrote on last edited by
          #4

          Well, that is why I would try to get rid of QtSerialPort, and try a generic Qt worker thread example to see if the problem persists. If not, try adding QIODevice through QFile for instance, if that does not reproduce the issue, you can add QtSerialPort. At least, that is how I would track this issue down without further clue. Also, I would try Linux and Mac as well just in case. It is a bit hard to proceed without localizing the issue. Furthermore, does it also happen for reading? Also, I am not sure why you have used moveToThread() for this scenario. Could you please comment on that?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            M4chin3
            wrote on last edited by
            #5

            Why not use moveToThread? I thought this would be a correct way in Qt.

            But i just saw i use the moveToThread()/creation of the Thread wrong. I'm creating my QTimer within the constructor, it doesn't work that way.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kuzulis
              Qt Champions 2020
              wrote on last edited by
              #6

              Seems, this problem is similar to:

              • http://qt-project.org/forums/viewthread/33142.
              1 Reply Last reply
              0
              • M Offline
                M Offline
                M4chin3
                wrote on last edited by
                #7

                Thanks kuzulls (again). I will check this tomorrow, the main problem is i didn't know how to work with threads correctly. I tried it with QSerialPort in the worker class and outside in the parent but always in the wrong way (creating the QTimer in the constructor of the worker, therefore the QTimer wasn't running in his own thread. It was still running in the parent thread). Shame on me.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  M4chin3
                  wrote on last edited by
                  #8

                  Hi,

                  moving the serialport correctly to a own QThread solved my problem or most of my problem. I now can reseize and move the window of my application as long as i want and it still sends data.

                  Another problem I found in this context is the following:
                  In Windows7 having classic style (Win2000 style) activated and checked the option "Animate windows when minimizing and maximizing" in the "Performance Options" the whole system will freeze while doing this animation. So running my program and minimizing or maximizing any (even of other processes) window will result in blocking my program. (it also seems to block the whole system)

                  I think this has nothing to do with Qt at all, this is OS related :-(

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    M4chin3
                    wrote on last edited by
                    #9

                    Has been added here:

                    https://bugreports.qt-project.org/browse/QTBUG-34946

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved