PDA

View Full Version : Crash on call to QInputDialog::getText -- in 4.7.1, new behavior since 2009.05



adamb924
9th January 2011, 13:08
I have the following call in a subclassed QDialog. It causes the program to crash. This is new since I upgraded from the old Qt I was using (2009.05; 4.6.something). Has anyone had a similar problem?



bool ok;
QString text = QInputDialog::getText(this, tr("Enter a new label"),
tr("Enter a new label"), QLineEdit::Normal,
"test", &ok);

tbscope
9th January 2011, 13:17
That seems correct code.

I guess the problem is either the "this" pointer, which I don't think is the case.
Or the problem is somewhere else.

adamb924
9th January 2011, 17:05
Some more interesting information...

My function call is in a slot that is called in response to a drag-and-drop event. If I call the slot from the constructor function (i.e., after everything is initialized), it doesn't crash.

I can also call getText one time from the slot when the slot is triggered by a signal. In the code block below, the program crashes on the second call to getText. I've got the debug lines in there to check if something is happening to the this pointer. In both cases it prints the appropriate window name.



bool ok;
qDebug() << "Check this:" << this->windowTitle();
QInputDialog::getText(this, tr("Enter a new label"),
tr("Enter a new label"), QLineEdit::Normal,
"test", &ok);
qDebug() << "Check this:" << this->windowTitle();
QInputDialog::getText(this, tr("Enter a new label"),
tr("Enter a new label"), QLineEdit::Normal,
"test", &ok);

adamb924
11th January 2011, 03:53
Well, just to finish off the thread, I was never able to figure this out. I'm just using Qt 4.6 for this project.

MarekR22
11th January 2011, 11:27
I think that problem is in some unfinished job in event loop you are in.
Note that QInputDialog::getText creates new event loop and probably some new event requires to end handling of previous event (drag and drop events probably).
So IMHO you should try one of two solutions:
1. connect this slot with: Qt::ConnectionType = Qt::QueuedConnection (fifth parameter of connect with default value Qt::AutoConnection).
2. emit signal in last possible moment (when everything is completed in handling drag and drop event).