Results 1 to 2 of 2

Thread: Need advice on usage of qextserialport class before the QApplication event loop

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2021
    Posts
    1
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Need advice on usage of qextserialport class before the QApplication event loop

    Hi,

    I have a requirement of sending serial commands and accept the response using qextserialport library on Qt4.

    I am trying to read/ write to/from the serial port using signals and slots mechanism. There are series of commands that need to be sent in-order to initialize the setup. For all the commands i send , i need to check for an acknowledgement. So, decided to define the Qtimer for a timeout. Both the Qtimer and the Qextserialport are using the signal and slots. The serial port read/write has to be done before the Qapplication event loop. As per my understanding of Qt, I presume, Signals and slots does not work without an event loop.

    Any suggestions on how to use the serial port library would be grateful.

    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Need advice on usage of qextserialport class before the QApplication event loop

    Signals and slots does not work without an event loop.
    That's correct.

    The serial port read/write has to be done before the QApplication event loop.
    This probably can't be done if the serial port class depends on a running event loop. QTimer won't work without an event loop either.

    I am sure what you want to do can be done after the event loop is started. If what you are trying to do is to perform the serial port setup before the main GUI becomes visible, that is certainly possible. Instead of calling mainWindow.show() just before the call to app.exec() in main(), define a different MainWindow slot that will handle your setup. Call that slot from main() instead. As soon as the event loop starts (app.exec()), that slot will be called. Do your setup in there. Define a signal for MainWindow that gets emitted after the setup is done, and connect that signal to the QMainWindow::show() slot.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 19th May 2021, 21:42
  2. Replies: 4
    Last Post: 16th June 2015, 18:50
  3. Replies: 4
    Last Post: 6th August 2011, 02:40
  4. Replies: 10
    Last Post: 15th January 2010, 15:35
  5. Replies: 0
    Last Post: 23rd October 2008, 13:43

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.