PDA

View Full Version : QList: unexplicable crash



pucara_faa
25th July 2010, 02:37
Hi everybody,
I'm having problems when using QList to generate run-time widgets. I create those widgets and store them inside the QList for later use.
In one of my dialogs I need to create one QSpinBox and one QLineEdit dynamically. When I create them, everything works fine, and they are shown, but when I close the dialog, the application crashes. Here's the explanation of what I'm doing:

I create in my header file the QList variable as following:

private:
QList<QLineEdit*> products;

And I use it in in the source file like this:
QLineEdit *qleProducts = new QLineEdit();
qleProducts->setCompleter(completer); //Sets widget custom completer, defined before, it works OK
layout->addWidget(qleProducts); //Adds the widget to a layout
products.append(qleProducts);

Then, compile, and everything works OK.
But the problem comes when I try to create another QList object.
In the header file I add:
QList<QSpinBox*> totals;

And in the source file:
QSpinBox *qsbTotals= new QSpinBox();
layout->addWidget(qsbTotals);
totals.append(qsbTotals);

Then, I compile the application, it compiles OK, I execute the dialog, creates and display the widgets OK, but when I close the dialog, the application crashes, returning code -1073741819 but no other error.

It seems that the program crashes when I have declared two QList variables in one file.
Maybe it is a QT bug, or I'm just missing something stupid.
Please, I need help, I really need to solve this.

I'm sorry for my poor English, I'm Argentinian.
Best regards,
Facundo

norobro
25th July 2010, 03:46
Don't see why what you described won't work. Can you post your project as an attachment?

pucara_faa
25th July 2010, 04:07
Don't see why what you described won't work. Can you post your project as an attachment?

Thanks for answering!
Ok, I'll post it tomorrow, now I haven't the project in this computer.
Greetings,
Facundo

squidge
25th July 2010, 09:16
Possible double free issue? Are you delete'ing those objects yourself as it seems they have no parent. If so, remove that code and see if it still crashes.

pucara_faa
25th July 2010, 15:09
Hi,
First of all, I want to thank both of you for answering, I solved the problem, (although don't know HOW). I changed the code a little and then rebooted my computer and WORKED! :cool:
I don't know what could it be.
Kind regards,
Facundo