PDA

View Full Version : Unhandled Exception Err



Masih
24th July 2007, 05:11
Hi

I was doing a tutorial http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html
and I did just some minor changes to the code.
After running the program I got an error. Seems that I am pointing to somewhere illegal or something! I attached the screen shot of the Error here.
Could you please tell me what is the reason of such errors?:confused:
Is it called runtime error or something else?!

Thx

marcel
24th July 2007, 05:56
In general, the reason for these errors is an uninitialized pointer.
The error is actually a memory violation resulted when the program tried to read from an unallocated memory address.

From what I have seen in the call stack, your problem is in a connect statement, in the constructor of myQtApp.
You are passing an invalid pointer as the sender.


Regards

Masih
24th July 2007, 06:08
In general, the reason for these errors is an uninitialized pointer.
The error is actually a memory violation resulted when the program tried to read from an unallocated memory address.

From what I have seen in the call stack, your problem is in a connect statement, in the constructor of myQtApp.
You are passing an invalid pointer as the sender.


Regards


These are the connects I am using in the program. Should the problem be by those pushButton_##s?


myQtApp::myQtApp(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)

{
ui.setupUi(this);
connect( pushButton_Browse,SIGNAL(clicked()),this,SLOT(getP ath()));
connect( pushButton_DoSomething,SIGNAL( clicked() ),this, SLOT( doSomething() ) );
connect( pushButton_Clear, SIGNAL(clicked()),this,SLOT(clear() ) );
connect( pushButton_About, SIGNAL(clicked()), this, SLOT(about()));
}

marcel
24th July 2007, 06:15
But where do you allocate pushButton_*?
They first have to be created.
So just do something like:


pushButton_Browse = new QPushButton("Browse", this);


Regards

Masih
24th July 2007, 06:30
But where do you allocate pushButton_*?
They first have to be created.
So just do something like:


pushButton_Browse = new QPushButton("Browse", this);


Regards

I used Qt-Designer to make the Ui. Isn't it correct that when making this Ui with drag and drop and then naming it, we actually create this Object off the heap?

Thx.

Masih
24th July 2007, 18:20
But where do you allocate pushButton_*?
They first have to be created.
So just do something like:


pushButton_Browse = new QPushButton("Browse", this);


Regards


They are in ui_myqtapp.h.



#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QSpinBox>
#include <QtGui/QTextBrowser>
#include <QtGui/QWidget>

class Ui_myQtAppClass
{
public:
QSpinBox *spinBox_2;
QSpinBox *spinBox;
QLabel *label;
QLineEdit *lineEdit;
QLabel *label_2;
QCheckBox *checkBox;
QComboBox *comboBox;
QLabel *label_3;
QPushButton *pushButton_DoSomething;
QPushButton *pushButton_Clear;
QPushButton *pushButton_About;
QTextBrowser *textBrowser;
QPushButton *pushButton_Browse;:confused:

marcel
24th July 2007, 18:40
I suggest to debug the myQtApp constructor.

Put a breakpoint in the first line (ui.setupUi(this)) - press F9 on that line.
Hit F5 to start debugging.
While you step over look at what addresses the three pointers have ( the QPushButtons ).

Check if either one of them is invalid.

Regards

Masih
25th July 2007, 20:18
I suggest to debug the myQtApp constructor.

Put a breakpoint in the first line (ui.setupUi(this)) - press F9 on that line.
Hit F5 to start debugging.
While you step over look at what addresses the three pointers have ( the QPushButtons ).

Check if either one of them is invalid.

Regards

Hi Marcel,

I did what you have recommended. Actually I didn't understand what the problem source could be. I just removes the "ui." from
ui.setupUi(this) and then everything was fine and no error happened!
first , Can you explain me why this ui. was the problem source?!
and second, do you have any source explaining the debugging techniques in MVSC ?
Thanks a lot in advance.
:o

jpn
25th July 2007, 21:20
There are two suggested ways of using designer components:

single inheritance approach (http://doc.trolltech.com/4.3/designer-using-a-component.html#the-single-inheritance-approach)
multiple inheritance approach (http://doc.trolltech.com/4.3/designer-using-a-component.html#the-multiple-inheritance-approach)

To me it sounds like these two approaches are getting mixed up.

marcel
25th July 2007, 21:28
Can you explain me why this ui. was the problem source?!

I think jpn's post explains it.



do you have any source explaining the debugging techniques in MVSC ?


Not really. It's everything pretty straightforward and it is depending on what you're looking for.
The most important are:
F10 - Step over
F11 - Step in
F5 - Continue.
Keep your eyes on the Autos, Locals, Call stack and Threads tabs.
And with Qt it is very useful to examine the Output tab since all debugging messages go there.

You can also add watches.

Another useful thing is the Quick Watch window - just position the cursor on a variable and press Alt-Q. Very good for arrays, classes, structs.

I guess you'll discover more of them as you proceed.

Regards