Active Topics

 



Notices


Reply
Thread Tools
Venemo's Avatar
Posts: 1,290 | Thanked: 1,753 times | Joined on Aug 2009 @ Budapest, Hungary
#1
This is a sample code from the application I'm currently working on.
The strings and the variable names are changed to make this sample more understandable.

(In fact, I'm working on an EVE Online API client, and this is the code which asks the user for his/her User ID and API key.)

Code:
if (QMessageBox::Yes == QMessageBox::question(this, "Do you agree?", "Terms of use", QMessageBox::Yes, QMessageBox::No))
{
    bool *ok = new bool;
    int id = QInputDialog::getInt(this, "An ID", "Please enter a number", 42, 1, 2147483646, 1, ok);
    if (*ok)
    {
        QString str = QInputDialog::getText(this, "A string", "Please enter a string", QLineEdit::Normal, "example", ok);
        if (*ok)
        {
            waitDialog->show();
            connector->callMethod(id, str);
        }
    }
    delete ok;
}
"connector" is an object which sends network replies, and interprets the replies, and "waitDialog" is a MessageBox instance which displays a "Please wait" dialog while the network reply arrives. (To prevent this bug from happening.)

I compiled it with MADDE's Qt Creator integration.
(The Qt version is 4.5.3, which is the default in PR 1.1.1.)
When the application reaches this code block and displays the message box and then the input dialogs, it randomly crashes when I click on one of their buttons.

There are no operations in the background, and nothing that would affect it.
At least 1 out of 5 times, it crashes either on clicking on the "Yes", or clicking on the "Done" of the first input dialog.
It has never crashed on the second input dialog, though.

I tried to change getInt() to getString(), and then converting the result to int, but the dialog also crashed then, too. (Also about 1 of 5 times.)

It seems that changing the MessageBox so that it only has a "Done" button makes it not crash, but then the first input dialog also crashes sometimes.

I think I may be doing something wrong here, but I can't find any specific reason for this behaviour.

Could anyone be so kind as to help me with that?

Last edited by Venemo; 2010-04-11 at 17:41.
 
Posts: 13 | Thanked: 12 times | Joined on Apr 2010 @ Finland
#2
Must be that 4.5.3 Qt as with 4.6.2 it works fine. Also could be your waitDialog or connector.
 
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#3
I reckon it will help if you can paste more of your source code here ( how exactly connector and waitDialog is defined and used etc and any other relevant parts.
what you have pasted seems ok to me, perhaps the core happens elsewhere.
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

I hear and I forget. I see and I remember. I do and I understand.
 
Venemo's Avatar
Posts: 1,290 | Thanked: 1,753 times | Joined on Aug 2009 @ Budapest, Hungary
#4
Okay.
The application will have a GPL (or EU-PL, haven't decided yet) license, so I uploaded the whole source code to this location.
It is a Qt Creator project file, which I run on the device using MADDE.
It might not be perfect yet, but take into account that this is my first real Qt application.
(And there are really too much TODOs in there.)

I also uploaded a 2 minutes long video file on which you can see the issue. It's here. It's a little blurry, but you can see what I'm talking about. It simply crashes at pressing "Yes" on the message box, or pressing "Done" on the first input dialog. It seems that the second input dialog never crashes, however.
On the video I managed to press the buttons without issue a few times, but sometimes the whole application just crashes for no reason when pressing them.
(And LOL, I accidentally clicked the Weather widget several times after it had crashed...)

The error occours in the MainWindow::addCharacter() method in the mainwindow.cpp.

However, I doubt that the connector or the waitDialog could be the issue, because it is also present when I comment them out.

Last edited by Venemo; 2010-04-11 at 21:45.
 
Venemo's Avatar
Posts: 1,290 | Thanked: 1,753 times | Joined on Aug 2009 @ Budapest, Hungary
#5
I forgot to mention: there are other oddities with the app, as well. For example, #if defined(Q_WS_MAEMO_5) doesn't work, and if I release the QNetworkReply* when I finished using it, the application crashes.
(These are commented in the souce code, if someone cares to look at it.)
 
Posts: 13 | Thanked: 12 times | Joined on Apr 2010 @ Finland
#6
Not sure but i think Q_WS_MAEMO_5 came in 4.6 and 4.5 has Q_WS_HILDON.
Still cant see reason why QMessageBox::question() would crash it. Does it crash in windows too? Maybe you could try debugging it with debugger to see what call crashes it?
 

The Following User Says Thank You to tommiasp For This Useful Post:
Venemo's Avatar
Posts: 1,290 | Thanked: 1,753 times | Joined on Aug 2009 @ Budapest, Hungary
#7
The debbugger doesn't work with Qt Creator and MADDE.
(Breakpoints don't work also.)
 
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#8
Ive had a quick look at your code, and i couldnt figure out anything inapprorpiate immediately. WIll try to have a closer look.
If you have time at hand now, why not comment each of those 3 Dialogs one by one and localize it.

comment out this as well in MainWindow::addCharacter(), since you said it occurs even without them.
// This is to prevent Maemo bug #9883
appMenu->setEnabled(false);
waitDialog->show();
connector->requestAccount(userId, apiKey);
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

I hear and I forget. I see and I remember. I do and I understand.

Last edited by krk969; 2010-04-12 at 13:47.
 

The Following User Says Thank You to krk969 For This Useful Post:
Posts: 17 | Thanked: 42 times | Joined on Feb 2010
#9
Originally Posted by Venemo View Post
...if I release the QNetworkReply* when I finished using it, the application crashes...
This is because you're deleting the reply in one of its slots. Instead of using the delete keyword, you want to call reply->deleteLater().
 

The Following User Says Thank You to StewartHolmes For This Useful Post:
Venemo's Avatar
Posts: 1,290 | Thanked: 1,753 times | Joined on Aug 2009 @ Budapest, Hungary
#10
Not sure but i think Q_WS_MAEMO_5 came in 4.6 and 4.5 has Q_WS_HILDON.
I'm surprised! Q_WS_HILDON just works. But why did they change it?
No matter, I now use the following:
Code:
#if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
So it will compile on 4.5 and 4.6 as well. Thank you!

Ive had a quick look at your code, and i couldnt figure out anything inapprorpiate immediately. WIll try to have a closer look.
Thank you very much for looking into it!
Did you watch the video recording?
Do the crashes happen on your device also, or is it only the fault of my device?

If you have time at hand now, why not comment each of those 3 Dialogs one by one and localize it.
This is a really nice idea, thanks for it! Of course I have the time.

After some testing and trying to localize the issue, it seems that QMessageBox doesn't crash by itself, however QInputDialog crashes gladly. After some trying, the debugger actually worked, and it said that a segmentation fault has occoured. (I attached a zipped screenshot about it.)
It seems that the error is in Qt's code, not mine. Can I do anything about it?

The question is, why aren't any of the errors caught by the try-catch block in main() ?

This is because you're deleting the reply in one of its slots. Instead of using the delete keyword, you want to call reply->deleteLater().
You also saved my day with this.
I didn't know about deleteLater(), the tutorial I saw used the delete operator.
(And it didn't crash the sample application which I made to test how it works.)

Big thanks again to all of you!
Attached Files
File Type: zip scr_qt_bug.zip (239.1 KB, 105 views)

Last edited by Venemo; 2010-04-12 at 14:38.
 

The Following User Says Thank You to Venemo For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 01:39.