QEventLoop usage(signals and slots)

691 views Asked by At

I have an application which contains such lines.

emit WindowAdded(settings->WindowType);//!!!!!!!!!!!!!!
MyWindow *widget = new MyWindow(0,settings,currentWindowIndex);

The signal changes value of currentWindowIndex, but it didn't work because of slot, it doesn't change its value in time. Some one advices me to use QEventLoop, but i don't understand how to do this. Give me an example, please. Another part of the code:

 connect(area,SIGNAL(WindowAdded(QString)),this,SLOT(addWindowOnTab(QString)));


void WorkSpace::addWindowOnTab(QString title)
{
    qint32 i = TabsList->addTab(title);/////!!!!!!!!!!!!!!!!!!!!!!!!!
    emit addedWindowIndex(i);
    TabsList->setVisible(true);
}

connect(this,SIGNAL(addedWindowIndex(qint32)),area,SLOT(WindowIndexChanged(qint32)));

void MyMdiArea::WindowIndexChanged(qint32 index)
{
    currentWindowIndex=index;
}

I think it can help.

MyMdArea is сlass inherited from QMdiArea, WorkSpace is a QWidget, TabsList is a QTabBar. And there is another fact: I tried to understand execution sequence of slots and added some lines to code:

QLabel *n= new QLabel("1");
n->show();

after emiting WindowAdded signal

QLabel *n= new QLabel("2");
n->show();  

after emiting addedWindowIndex signal

and

QLabel *n= new QLabel("3");
n->show();

after changing currentWindowIndex's value

and that is what i saw "1 2 3" and its exploded my brain. Maybe i don't understand something?

0

There are 0 answers