0

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?

zuzman322
  • 124
  • 8
  • A signal does not change a value. As for the slot, you have not showed the connect statement, nor the slot definition, etc. It is not possible currently to give an accurate answer. – László Papp Dec 25 '13 at 11:53
  • It's a little bit complicated becouse of signal connected with slot, that emit signal, that change this value, if you need it a can post all parts of code, but few huors later. – zuzman322 Dec 25 '13 at 11:58
  • We need a simple code reproducing the issue: sscce.org. Currently, there can be too many things going wrong based on your question. We do not know anything about WindowAdded, MyWindow, your slot, etc. – László Papp Dec 25 '13 at 12:00
  • In case you don't explicitly use Qt::QueuedConnection or multithreading, the slots are executed synchronously where you emit WindowAdded(). – Frank Osterfeld Dec 25 '13 at 17:25
  • if `MyWindow` is derived of `QWidget` then you have to have a `QApplication` instance running and the applicaiton instance has a event loop running for you ... so we need more code to make clear what is going on here – Zaiborg Dec 25 '13 at 19:07
  • user3081564, do not forget to paste more code. :) – László Papp Dec 26 '13 at 04:15
  • Sorry to trouble. I solve this problem. The problem was in the wrong algorithm. So I wrote new algorithm and now it works)) – zuzman322 Jan 10 '14 at 12:03

0 Answers0