Results 1 to 10 of 10

Thread: doubt in blocking fortune client example

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default doubt in blocking fortune client example

    hi friends,
    for learning threads i am going on the blockingfortune client ..
    i am trying to find why they use cond.wakeOne()
    can anybody please explain clearly of QWaitCondition() on blocking fortune client example ... the step i try to follow in assistant docs cant help me .. can u guide a little about it please ....
    the main doubt is whn ever the user clicks getFortune a new thread will create ..?
    Last edited by wagmare; 19th February 2009 at 10:47.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: doubt in blocking fortune client example

    no, whenever the user clicks the button, the button gets disabled and the same thread would start or restart and wait for a new fortune to come and as soon as it comes, it will emit a newFortune() signal with the fortune string, which is then caught by the blocking client and shown

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: doubt in blocking fortune client example

    thanks for the reply first ..
    why we have to use this QWaitCondition ...
    as
    void QWaitCondition::wakeOne ()
    Wakes one thread waiting on the wait condition. The thread that is woken up depends on the operating system's scheduling policies, and cannot be controlled or predicted.
    If you want to wake up a specific thread, the solution is typically to use different wait conditions and have different threads wait on different condition
    .

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: doubt in blocking fortune client example

    in this example, waitOne() is used to wake up Fortune Thread itself cuz that is the only thread that goes on a wait, right? whenever a required condition is met, the thread is awakened from sleep/wait using wakeOne()

  5. The following user says thank you to talk2amulya for this useful post:

    wagmare (19th February 2009)

  6. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: doubt in blocking fortune client example

    Quote Originally Posted by talk2amulya View Post
    in this example, waitOne() is used to wake up Fortune Thread itself cuz that is the only thread that goes on a wait, right? whenever a required condition is met, the thread is awakened from sleep/wait using wakeOne()
    thanks for reply ... i get it

    i am not familiar in qt threads so only i ask this question ...
    without it will create a problem? in this case if we dont try to do that what it will result ...
    because i show the piece of code to my project manager and he ask the question why should you wait for another thread as only one thread is on progress so only i ask the question .

  7. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: doubt in blocking fortune client example

    here i am planning
    => a main thread class Dialog() having four buttons
    => a worker thread class Thread() will do all the operation of the buttons and emit the output ... single thread ..
    =>i will call Thread() function calls in the Dialog() with arguments corresponding
    to the user clicks button
    =>the Thread in response emit corresponding signals from the argument


    now in Thread() i have to use wakeOne() condition ... ? why ?

    please give some suggestion ... i am still not cleared ..

  8. #7
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: doubt in blocking fortune client example

    well, u r missing one very important thread the MAIN thread that runs with the main function..but thats not the point..the working of it is like..when u click the button, it gets disabled, thread is awakened(from wait) or started, it connects with the host, gets a fortune and emits a signal with the fortune string..the blocking client gets the signal, shows fortune or the error thrown and enables the button again..now u see the point?

  9. #8
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: doubt in blocking fortune client example

    perfect .. and tomorrow i will expain him clearly .. thank you amulya ...

  10. #9
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: doubt in blocking fortune client example

    u can thank my by clickin on that shiny "thanks" button down there (i m not queer, just having a bet )

  11. #10
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: doubt in blocking fortune client example

    Quote Originally Posted by talk2amulya View Post
    u can thank my by clickin on that shiny "thanks" button down there (i m not queer, just having a bet )
    clicking a button is not like my words of thanks ... it echos dynamically to my helping friends ..

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.