Results 1 to 5 of 5

Thread: Why my object stay in main thread?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Why my object stay in main thread?

    I puzzled with 4 and 5. I have used moveToThread function to move the m_spDevPort to the monitor thread, but its member m_spSerialPort still stayed in the main thread.
    your problem is that m_spSerialPort's parent is not set.

    Qt Code:
    1. CSerialPort::CSerialPort()
    2. {
    3. // Create serial port object
    4. m_spSerialPort = new QSerialPort(this); //<<<<<<<<<<<<<<<< Pass the parent while object creation.
    5. // 1. print the thead where m_spSerialPort lived in
    6. printThreadID();
    7.  
    8. // Timer for send command
    9. m_tQueryTimer = new QTimer;
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  2. The following user says thank you to Santosh Reddy for this useful post:

    honestapple (2nd April 2013)

  3. #2
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 43 Times in 42 Posts

    Default Re: Why my object stay in main thread?

    I wanted to create a serial port monitor thread. I used QT4.8.6 + QSerialPort(latest) on Windows XP.
    Using the QSerialPort library is not good idea.

    Is better to use - QtSerialPort library.

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Why my object stay in main thread?

    Using threads is probably unnecessary also.

  5. #4
    Join Date
    Jan 2013
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    8

    Default Re: Why my object stay in main thread?

    Yes, it is QtSerialPort library.


    Added after 26 minutes:


    Yes, I knew that you have mention that. I am doing a USB DAQ GUI part on PC using QT4.8.6+QWT6.0.2 under Windows XP. I should receive data from device and display waveform, frequency spectrum, etc. I have made a demo without threads which could receive and send command( using timer ) at a interval, but I could not display the wavefrom in realtime. In fact, it was not that the waveform could not be displayed completly. It is sometimes good, sometimes bad. When it was bad, I knew that there are something wrong with the QwtCPointerData. Because there are many operation in main GUI thread, I wanted to tried to use monitor thread to release GUI thread from doing data receiving and sending command.
    Last edited by honestapple; 3rd April 2013 at 04:29.

Similar Threads

  1. Replies: 11
    Last Post: 27th January 2013, 12:47
  2. Replies: 1
    Last Post: 28th March 2012, 18:58
  3. Replies: 5
    Last Post: 22nd February 2011, 21:21
  4. Replies: 9
    Last Post: 28th November 2009, 20:31
  5. Replies: 16
    Last Post: 7th October 2009, 08:17

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.