PDA

View Full Version : Run-time error in QWizardPage when I connect a signal to a slot, and page is canceled



falconium
9th April 2011, 00:55
Hi,

PageCounter is a QWizardPage of a QWizard. This is the slot I'm using in it:


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(select edItem)));
}

Signal is a QComboBox currentIndexChanged(int) defined in PageCounter constructor:


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!

falconium
9th April 2011, 05:24
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:

falconium
9th April 2011, 08:08
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?

falconium
9th April 2011, 17:51
:( Nobody knows it?

zenzero-2001
9th April 2011, 18:04
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 :)

falconium
9th April 2011, 19:13
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.

zenzero-2001
9th April 2011, 20:23
Glad you got it fixed.