SetupUi gives troubles with my class
-
For a new project I started, I decided to use Qt, since a friend of mine kept going on about it. So, bear with me, I'm still rather new to this.
Ok, I defined a class (in this case called DNAViewer) and I've made a nice UI using designer. So now I wish to use setupUi() and I parse it 'this' as an argument. My class is defined as
@
class DNAViewer : public QWidget , private Ui::DNAViewerUIDLG{
Q_OBJECTpublic:
DNAViewer(QWidget *parent = 0);...
};
@Now, as far as I know, if I call setupUi(this) in the constructor (seen below), this should work, right?
@
DNAViewer::DNAViewer(QWidget *parent){
setupUi(this); // this sets up GUI...
}
@
Any help would be greatly appreciated. -
I get the following:
_
DNAViewer.cpp: In constructor ‘DNAViewer::DNAViewer(QWidget*)’:
DNAViewer.cpp:6:17: error: no matching function for call to ‘DNAViewer::setupUi(DNAViewer* const)’
ui_DNAHilbertViewerUI.h:37:10: note: candidate is: void Ui_DNAViewerUIDLG::setupUi(QDialog*)
_Which I don't completely get, since there is a perfectly fine setupUi() function which takes a QWidget...
-
You created a UI based on a QDialog in Qt Designer. So you must inherit from QDialog in your DNAViewer class too (instead of QWidget).
Just change dnaviewer.h to
@
class DNAViewer : public QDialog , private Ui::DNAViewerUIDLG{
Q_OBJECT
public:
DNAViewer(QWidget *parent = 0);
...
};
@and dnaviewr.cpp to
@
DNAViewer::DNAViewer(QWidget *parent)
: QDialog(parent)
{
setupUi(this); // this sets up GUI
...
}
@Pleas do not forget to call the base class constructor with the parent! That's always necessary for QObject based classes, which include QWidget and QDialog!