Results 1 to 3 of 3

Thread: QSerialDevice cause GUI to freeze

  1. #1
    Join Date
    Sep 2010
    Location
    Russia, Moscow
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSerialDevice cause GUI to freeze

    Hi all I have another problem. maybe someone seen this before....

    I'm using QSerialDevice lib to communicate with GPS reciever over COM port. All work with this lib i've moved to thread.

    Very very simplified class looks like this:
    header:
    Qt Code:
    1. class testThread : public QThread
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. testThread(){};
    7. protected:
    8. virtual void run();
    9. private slots:
    10. void trigged();
    11. private:
    12. AbstractSerial *as;
    13. };
    To copy to clipboard, switch view to plain text mode 

    cpp:
    Qt Code:
    1. void testThread::run()
    2. {
    3.  
    4.  
    5. QTimer *timer = new QTimer(this);
    6. connect(timer, SIGNAL(timeout()), this, SLOT(trigged()));
    7. timer->start(10000);
    8.  
    9. as = new AbstractSerial(this);
    10. as->setDeviceName("COM3");
    11.  
    12. exec(); // begin eventloop
    13. }
    14.  
    15. void testThread::trigged()
    16. {
    17.  
    18. if (!as->isOpen())
    19. {
    20. if (as->open(AbstractSerial::ReadOnly))
    21. {
    22. QMessageBox *msg = new QMessageBox();
    23. msg->setText( " opened ");
    24. msg->show();
    25. }
    26.  
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 

    Thread starts, after 10 seconds timer emit signal timeout and all GUI freeze... After it leave trigged func everything woks normal until next emit
    Any ideas? Problem in lib or ...?

    update:
    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is testThread(0xba2af8), parent's thread is QThread(0xad7938), current thread is testThread(0xba2af8)

    this was in console. What does it mean?

    update:
    problem solved:
    Qt Code:
    1. testThread thrd = new testThread();
    2. thrd->moveToThread(thrd);
    To copy to clipboard, switch view to plain text mode 
    is it correct?
    Last edited by dkoryagin; 26th September 2010 at 13:44.

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

    Default Re: QSerialDevice cause GUI to freeze

    No, you're doing it wrong. And after moveToThread() you'll be accessing GUI from non-gui thread.
    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
    Sep 2010
    Location
    Russia, Moscow
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSerialDevice cause GUI to freeze

    I think i've posted bad example of class
    There is no GUI connection between threads...No messageboxes....Connection between gui and thread inplemented by signals.

    Thanks, wysota.

Similar Threads

  1. QSerialDevice v 0.2.0 released
    By kuzulis in forum Qt Programming
    Replies: 23
    Last Post: 18th September 2010, 23:30
  2. QSerialDevice Problem
    By waynew in forum Qt Programming
    Replies: 8
    Last Post: 21st January 2010, 14:31
  3. QSerialDevice
    By clinisbut in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2009, 13:30
  4. [solved] QSerialDevice: How to set baudrate?
    By schlingel in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2009, 11:52
  5. new library QSerialDevice
    By kuzulis in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2009, 05:42

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.