Problem with QT / Threads / Signals / Slots

Discussion in 'C++' started by Frank Bossy, Jul 9, 2003.

  1. Frank Bossy

    Frank Bossy Guest

    Dear group :)

    I don't quite understand the meaning of this paragraph in the qt docu
    (http://doc.trolltech.com/3.1/threads.html):

    ***SNIP
    The Signals and Slots mechanism can be used in separate threads, as
    long as the rules for QObject based classes are followed. The Signals
    and Slots mechanism is synchronous: when a signal is emitted, all
    slots are called immediately. The slots are executed in the thread
    context that emitted the signal.
    ***SNIP

    Part of my program consists of the following code:
    bool
    MyBUE::stopServer()
    {
    QProcess* proc = sd.getProcess(); // already running process
    connect(proc, SIGNAL(processExited()), this,
    SLOT(aServerHasDied()));
    proc->kill();
    cout << "###############1" << endl;
    int counter = 10; // seconds
    cout << "###############2" << endl;
    while (proc->isRunning()) {
    cout << "###############3" << endl;
    m_waiter.wait(1000/*ms*/); // A QWaitCondition
    cout << "###############4" << endl;
    if (counter-- == 0) break;
    cout << "###############5" << endl;
    }
    if (proc->isRunning()) {
    cout << "###############6" << endl;
    cout << "Could not terminate process." << endl;
    cout << "###############7" << endl;
    return false;
    }
    cout << "Server terminated by stopServer." << endl;
    cout << "###############8" << endl;
    return true;
    }

    void
    MyBUE::aServerHasDied()
    {
    m_waiter.wait(5000/*ms*/);
    cout << "###XXX###" << endl;
    }

    I get the following result:

    ###############1
    ###############2
    ###############3
    <NO PAUSE!?>
    ###############4
    ###############5
    <5 SECONDS PAUSE>
    ###XXX###
    Server terminated by stopServer.
    ###############8


    Could please someone explain to me this behaviour? I don't understand
    it :(

    Any help would be greatly appreciated :)

    bye,
    Frank Bossy
     
    Frank Bossy, Jul 9, 2003
    #1
    1. Advertising

  2. "Frank Bossy" <> wrote...
    > Dear group :)


    Dear Frank,

    >
    > I don't quite understand the meaning of this paragraph in the qt docu
    > (http://doc.trolltech.com/3.1/threads.html):
    > [...]


    Qt, threading, Slots, and related things are not defined by the
    C++ language. They happen to be, therefore, outside the scope
    of this newsgroup. Perhaps there is a better place to ask your
    question, like the TrollTech tech support or, maybe the newsgroup
    for your platform... Or even their web site, where I managed to
    locate this archive: http://lists.trolltech.com/qt-interest/ ...

    Victor
     
    Victor Bazarov, Jul 9, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tin gherdanarra

    slots? SLOTS?

    tin gherdanarra, Oct 12, 2005, in forum: Python
    Replies:
    2
    Views:
    2,313
    Peter Hansen
    Oct 13, 2005
  2. Christian Bruckhoff

    Problems with Signals & Slots of QT

    Christian Bruckhoff, Sep 24, 2006, in forum: C++
    Replies:
    5
    Views:
    411
    loufoque
    Sep 24, 2006
  3. Brian Vanderburg II

    Signals/Slots support in Python

    Brian Vanderburg II, May 1, 2008, in forum: Python
    Replies:
    0
    Views:
    265
    Brian Vanderburg II
    May 1, 2008
  4. Alex M.
    Replies:
    4
    Views:
    475
    Rolf Magnus
    Aug 2, 2010
  5. lolveley
    Replies:
    6
    Views:
    183
    Stefano Crocco
    May 13, 2009
Loading...

Share This Page