Results 1 to 13 of 13

Thread: do control return back returning to previous slot/function from where signal generate

  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default do control return back returning to previous slot/function from where signal generate

    hello everybody,
    I have a place in code shown below where slot emits dataAvailable(). After that control will pass to corresponding slot. Do control returns back after execution of that slot.

    Qt Code:
    1. void MyThread::run()
    2. {
    3.  
    4.  
    5.  
    6. int fd0 = open("/home/prince/mydev01",O_RDWR|O_NONBLOCK);
    7.  
    8. while( ! _end )
    9. {
    10. read(fd0,&x,sizeof(int));
    11. read(fd0,&y,sizeof(int));
    12. emit dataAvailable();
    13. _semaphore.acquire();
    14. }
    15. close(fd0);
    16.  
    17. emit stopThreadSignal();
    18. cout<<"\tdataAvailable called";
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    In this case dataAvailable() leads to
    Qt Code:
    1. void MyDialog::receiveOnRead()
    2. {
    3.  
    4. QString sx;
    5. sx.setNum(mth.x);
    6. QString sy;
    7. sy.setNum(mth.y);
    8. label->setText(sx+QString(" ") +sy);
    9. cout<<"From dialog thread"<<mth.x<<" "<<mth.y;
    10. }
    To copy to clipboard, switch view to plain text mode 

    It just replaces the lable text.

    Well i am sorry i keep asking such related questin again n again but ihave some doubts still prsisting. I have tried with some test pgms which donot make concept clear.
    Last edited by quickNitin; 12th June 2006 at 10:41. Reason: change in code

  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: do control return back returning to previous slot/function from where signal gene

    If Qt3 -- yes. In Qt4 -- it depends if a connection is direct (yes) or queued (no).

  3. #3
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: do control return back returning to previous slot/function from where signal gene

    and in my case since signal connecting to a slot of object in different thread so it is queued. Is there any way to change this behaviour.
    Or there any other way for acheieving what i want? I want control to go back to next instruction in run() after emission of signal. Is it possible in Qt?

  4. #4
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: do control return back returning to previous slot/function from where signal gene

    Quote Originally Posted by quickNitin
    I want control to go back to next instruction in run() after emission of signal. Is it possible in Qt?
    well what you want is something similar to racing... a bad design problem. I would suggest that you try re-engineering the solution. Imagine the magnitude of the problem if what you were developing were a software for NASA!!

    This is what i suggest, rest is upto you.

    Nupul

  5. #5
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: do control return back returning to previous slot/function from where signal gene

    i will try, but my question still exists. Can you suggest me anything.
    One more question do event loop of thread starts by default or we have to use exec() as for queued connections.

  6. #6
    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: do control return back returning to previous slot/function from where signal gene

    I can only suggest that you use a wait condition to stop the emiting thread and release it from a slot. It's still a bad design though, because you may experience unwanted behaviour when two objects are connected to that signal.

    Qt Code:
    1. connect(thread, SIGNAL(someSignal()), someother, SLOT(someSlot()));
    2. //...
    3. void MyThread::someMethod(){
    4. m.lock();
    5. emit someSignal();
    6. wcond.wait(&m);
    7. m.unlock();
    8. }
    9. //...
    10. void OtherClass::someSlot(){
    11. doSomething();
    12. wcond.wakeAll();
    13. }
    To copy to clipboard, switch view to plain text mode 

    I don't know what will happen if the slot will be called immediately after emit someSignal(), before wcond.wait() -- you might end up in a deadlock. You might want to take a look at QWaitCondition docs to see how to avoid it.

  7. #7
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: do control return back returning to previous slot/function from where signal gene

    i agreed to it as bad design approach . Any suggestion on any articles/papers where i can improve my knowledge

  8. #8
    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: do control return back returning to previous slot/function from where signal gene

    Quote Originally Posted by quickNitin
    i agreed to it as bad design approach . Any suggestion on any articles/papers where i can improve my knowledge
    Depends on what you want to achieve.

  9. #9
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: do control return back returning to previous slot/function from where signal gene

    i will represent a analogy to my problem.
    Ya ealier all those suggestions were not with me . I am integrating them .
    For example say i have a plane ( i is getting much much exaggarated). Now at airtraffic control tower i have data (i think they have antenna ormay be through satellite ,don't know). I want to display that on map. Now there can be many planes also. I was thinking each thread will handle each such instance and report data availabitlity to gui thread.Currently as you had already answere it is bad design. I am looking for suggestion on such approach.

    Well i donot have that fast data as fast location of plane and no such consistent availability also.
    Last edited by quickNitin; 13th June 2006 at 10:29. Reason: change of post

  10. #10
    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: do control return back returning to previous slot/function from where signal gene

    But why do you need one of the threads to wait for the other?

  11. #11
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: do control return back returning to previous slot/function from where signal gene

    no i donot want thread to wait. only thing i want is simultaneous reading from fifo or socket and availability of newly read data in gui thread. I think i have been misunderstood here i want thread to wait.
    Anyways on my uniprocessore machine one of the thread will wait when other is running.
    Last edited by quickNitin; 14th June 2006 at 03:34. Reason: addition to post

  12. #12
    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: do control return back returning to previous slot/function from where signal gene

    Quote Originally Posted by quickNitin
    Anyways on my uniprocessore machine one of the thread will wait when other is running.
    But you won't know in what moment will it happen and this can lead to race conditions.

  13. #13
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: do control return back returning to previous slot/function from where signal gene

    agreed to it.

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.