blocking connect()



  • connect(&server,SIGNAL(display()),this,SLOT(display()));
    if display() signal is emitted, display() slot will be executed.
    so now i want the display() slot to block the program until it returns.
    how do i do that?
    TIA.


  • Moderators

    Your program will block as long as display() does not return.
    There is no need to do something special to block your program, even if it sounds strange why you want it to block.



  • @jsulm
    I tested it, it doesnt block the program
    emit display();
    qDebug() << "Message received!";
    output:
    Message received!
    contents of display() slot

    ive search around while waiting for answers in this thread.
    can you tell me the use of Qt::BlockingQueuedConnection?

    TIA


  • Moderators

    Emitting a signal in a single thread is basically calling a function, so it is blocking. The output you have can happen if "server" and "this" objects live in different threads. Is that the case?

    Qt::BlockingQueuedConnection is only useful if sender and receiver live in different threads. It makes the sender block on emit until receiver executes the slot. In a single threaded execution this is how emit behaves out of the box.



  • @Chris-Kawa
    my sender and receiver is in different thread.
    I see! you hit all the bullseye!
    THanks guys!

    and i now understand the Qt::BlockingQueuedConnection


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.