Run-time error in QWizardPage when I connect a signal to a slot, and page is canceled
Hi,
PageCounter is a QWizardPage of a QWizard. This is the slot I'm using in it:
Code:
void PageCounter::refreshDescription(int selectedItem)
{
// this changes the text of a QPlainTextEdit based on the selected item in QComboBox:
plaintextDescriptionOfSelectedCounter->setPlainText(wizard->caller->getCounterDescription(originalCounterIDs.at(selectedItem)));
}
Signal is a QComboBox currentIndexChanged(int) defined in PageCounter constructor:
Code:
connect(comboCounters, SIGNAL(currentIndexChanged(int)), this, SLOT(refreshDescription(int)));
Everything works, except if I cancel the wizard, then it crashes the whole program.
Maybe I should disconnect the signal, but I don't know where. This is the only clue I have, since it had been working perfectly before I added connect.
Thx!
Re: Run-time error in QWizardPage when I connect a signal to a slot, and page is canc
Code:
PageCounter::~PageCounter()
{
disconnect(comboCounters, SIGNAL(currentIndexChanged(int)), this, SLOT(refreshDescription(int)));
}
I have put it into the destructor, but still the same. :(
Please, help, I cannot debug it, it simply crashes... :confused:
Re: Run-time error in QWizardPage when I connect a signal to a slot, and page is canc
This has also appeared in Application Output tab.
ASSERT failure in QList<T>::at: "index out of range", file d:\Qt\2010.05\qt\include/QtCore/../../src/corelib/tools/qlist.h, line 455
It looks like QComboBox is destroyed sooner than SIGNAL/SLOT connection - just a guess. How could I avoid this?
Re: Run-time error in QWizardPage when I connect a signal to a slot, and page is canc
Re: Run-time error in QWizardPage when I connect a signal to a slot, and page is canc
Hi,
I don't know the answer to your problem. But I think the argument for setPlainText could be a bit suspect. It is possible that wizard could be a null pointer? Sorry if I'm stating something you have already thought of :)
Re: Run-time error in QWizardPage when I connect a signal to a slot, and page is canc
zenzero-2001 Thank you!
This is exactly what I have been thinking about, so I have changed the parameter of setPlainText to display only selectedItem as QString. And voila! It worked. After this, I moved originalCounterIDs under QWizard object as public from QWizardPage just to see if I can avoid it to be destroyed. Didn't help.
It should be the case as you said, that wizard object is destroyed sooner then the SLOT/SIGNAL connection. Isn't it a bug of Qt?
Or do you think there is a workaround?
Thanks for checking this issue!
Added after 37 minutes:
I have solved it.
The problem was that the passed selectedItem from QComboBox was -1, so this index couldn't be selected from QStringList.
It looks like the combobox selection is set back to -1 before destroying the combobox, and this implies the signal currentItemChanged emitted.
Solution was to check selectedItem value in SLOT.
Re: Run-time error in QWizardPage when I connect a signal to a slot, and page is canc