PDA

View Full Version : Opening a new window



k12yp70n
26th March 2009, 14:50
Hi there, folks!!

I have a bit of a problem here with being able to declare an object from a class derived from a UI file designed with Qt Designer, in other words:

in adddialog.h,


#ifndef ADDDIALOG_H
#define ADDDIALOG_H
#include "ui_adddialog.h"

class adddialog : public QDialog, private Ui::AddDLG {
Q_OBJECT
public:
adddialog ();
};
#endif // ADDDIALOG_H


in adddialog.cpp,


#include "adddialog.h"

adddialog::adddialog() {
setupUi(this);
}

and in the implementation of the main window,


#include "adddialog.h"
...
void mainwindow::adddialog() {
adddialog add;
add.show();
}


void adddialog in the class mainwindow is a slot, later used to connect a button to it, and hence make an "Add Dialog" launch whenever the button is clicked.
When I run this code I get the following errors:

"expected ; before 'add' "
"statement cannot resolve address of overloaded function"
" 'add' was not declared in this scope"

What am I doing wrong??? As usual sample code would be very appreaciated.

Thanks in advance

jpn
26th March 2009, 15:31
Rename function mainwindow::adddialog(), it conflicts with the class of the same name. Furthermore, the dialog goes immediately out of scope according to normal C++ rules. You should either use blocking exec() or allocate it on the heap, depending on whether you want it to be model and modeless.