Results 1 to 5 of 5

Thread: Another multithreading problem

  1. #1
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Another multithreading problem

    It seems it's quite annoying to use the multithreading features in Qt.
    Here is another problem:

    in class A, I have functionA(), functionA will call a static function functionB() in class B.
    It seems I can not run functionA() in another thread,
    the error is
    QObject::setParent: New parent must be in the same thread as the previous parent

    if I do not call B::functionB(), it works fine.

    any ideas?

  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: Another multithreading problem

    What's inside functionB()?

  3. #3
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Another multithreading problem

    Quote Originally Posted by wysota View Post
    What's inside functionB()?
    functionB is a pretty complex function, it's a function in Controller, will deal with datamodel and low level libraries(to control usb hardware) .

    Btw, it's run time error, no error during compilation.
    Last edited by Sheng; 30th October 2008 at 20:38.

  4. #4
    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: Another multithreading problem

    Inside the function you surely create some QObject subclass instance passing a parent object that was created in another thread and that's the problem. I suggest you post the function so that we can discuss how to improve it.

  5. #5
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Another multithreading problem

    Quote Originally Posted by wysota View Post
    Inside the function you surely create some QObject subclass instance passing a parent object that was created in another thread and that's the problem. I suggest you post the function so that we can discuss how to improve it.
    The only suspicious part of the function is I called a static function of QThread subclass SleeperThread(self defined) to implement sleep function. The other part is just call low level library, after get parameters, will update DataModel which emit signals to update GUI.
    I solved the problem by instead of running functionA in a new thread, making some changes in functionA, directly calling functionA and generate a new thread in functionA to run B::functionB. And it works fine.

Similar Threads

  1. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  4. Multithreading problem
    By y.shan in forum Qt Programming
    Replies: 4
    Last Post: 13th December 2007, 12:21
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.