Results 1 to 8 of 8

Thread: Non GUI threads

  1. #1
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Non GUI threads

    Hi,
    I wanted to pop-up a message box from pthread


    Qt Code:
    1. //my main process
    2. {
    3. //calling a function say f1();
    4. }
    5.  
    6. //in f1() I am creating a pthread
    7. {
    8. if (0!=pthread_create(&AnsiCommon.BALthread,NULL, Dys_BalThread,NULL))
    9. {
    10. qDebug()<<"draw bal thread";
    11. //fprintf(AnsiCommon.fpLogPI,"ECG Thread error\n");
    12. }
    13. }
    14.  
    15. //my thread function Dys_BalThread doing some calculations:After satisfying some conditins i wanted to pop-up a message box
    To copy to clipboard, switch view to plain text mode 

    can anybody help me.....?
    Last edited by Lykurg; 21st July 2011 at 08:10. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Non GUI threads

    Why are you using pthread directly and not Thread related Qt classes?
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Non GUI threads

    I am basically working on Linux platform.And it more concerned about hardware.In my pthread i am reading data from a serial port . Meanwhile at the end we have to port my application to a small embedded environment. Thats why I thought of preferring pthread rather than qtclases.I hope you understand my point.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Non GUI threads

    I hope you understand my point.
    I don't.
    Your concerns with hardware are irrelevant, if you have chosen to use Qt, and if you do, then use QThread.
    Linking to Qt but not using some classes makes no sense, and hardware plays no role for that.
    If you are not using Qt, why do you post under Qt Programming?

    Also, you only stated what you wanted to do.
    But what is the question?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Non GUI threads

    Ok..Ok...I can uderstand your saying.But i just wanted to do it from pthread only by using metaobjectsystem.(queuedconnections,postevents)
    plz help me.

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

    Default Re: Non GUI threads

    Quote Originally Posted by raghavendraningoji
    ...i wanted to pop-up a message box...
    I hope you are referring to the use of QMessageBox
    You can always use any native programming interfaces in your program, but when you want to use certain features of the a framework, you need to fit into the requirements of the framework. (I also hope you understand that when you create a thread using QThread or pthread, both will eventually create a native thread instance, so I don't understand your concern)

    It should be possible to trigger (indirectly, not directly), a QMessageBox from a thread started using pthread, but when you use pthread interface to create thread, the thread will not have meta object information of itself, so I don't see a way to emit signals (queued / direct) from a thread created using native interface. Try searching for "emit signals from native thread"

    (I also hope you understand the difference between signal and event)

    I believe one could send an event to GUI thread, and have a event handler in the GUI thread receive the event and do what so ever wanted

    I never personally tried this, though I had an opportunity to do so (because I din't want to complicate my program, and is harder to maintain), you can try this

    //somewhere in your thread (so called non-gui thread)
    1. When ready to pop up a message box, create a custom event (this has to be QEvent based object), say (popupEvent), on heap
    2. Get handle for the guiObject
    3. then post the event to the object (QApplication:: postEvent(guiObject, popupEvent)), this is static call so no need of application instance. (but it is assumed that you do have a instance of application created)

    //somewhere in GUI thead
    1. Create a QObject based class, and have a object of it (say guiObject)
    2. Implement a event handler in this class, which will handle a the custom event to poop-up a message box
    3. Then you are done, just create and show a QMessage when the popupEvent is received, with the content / message sent in popupEvent

  7. #7
    Join Date
    Jul 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Non GUI threads

    Thank you very much.Let me try this.

  8. #8
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Non GUI threads

    I think its easier to use signals and slots (via Queued Connection) to communicate between 2 threads. but perhaps (just a guess) you need for both solutions a custom event handling if pthreads are used (QEventLoop)

Similar Threads

  1. Qt Threads vs Native Threads performance
    By StackOverflow in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2010, 12:14
  2. Threads in Qt
    By freekill in forum Qt Programming
    Replies: 4
    Last Post: 11th November 2009, 18:49
  3. Qt threads
    By ^Nisok^ in forum Newbie
    Replies: 12
    Last Post: 22nd April 2009, 14:35
  4. Threads...
    By Abc in forum Qt Programming
    Replies: 1
    Last Post: 19th June 2008, 17:35
  5. Once more: Threads in Qt4
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 9th August 2006, 18:35

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.