Program closes too soon
-
Hi , you do not need UI but!
if you just have
QTextEdit *int1box; in djdialog1.h, you need to allocate a real objects before use. This is just a definition of a pointer.// somewhere else
int1box = new QTextEdit (this);You use use Designer then all Widgets u place on a form is available via
UI->the_namePlease notice those are only valid after
setupUi(this);@mrjj said in program closes too soon:
Hi , you do not need UI but!
if you just have
QTextEdit *int1box; in djdialog1.h, you need to allocate a real objects before use. This is just a definition of a pointer.// somewhere else
int1box = new QTextEdit (this);You use use Designer then all Widgets u place on a form is available via
UI->the_namePlease notice those are only valid after
setupUi(this);In "setupui, this line: answerbox = new QTextEdit(djdialog1); creates the object. Adding Ui-> in front of answerbox causes an error.
-
It would appear that setupUi is not being called. Here is my main.cpp:
#include <QApplication> // following 2 lines are initially here to build the "project" //#include <QDialog> //#include "ui_djdialog1.h" // following line replaces the above 2 lines #include "djdialog1.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); /** original code before 1st qmake-qt4 my.pro Ui::djdialog1 ui; // define an object named "ui" as being a djdialog1 QDialog *mydialog = new QDialog; ui.setupUi(mydialog); */ // following line is new (after initial make) djdialog1 *mydialog = new djdialog1; mydialog->show(); return app.exec(); }
I got this from a Qt tutorial.
[Added code tags ~kshegunov]
-
Hi
It seems you did already call it the normal place ?
djdialog1::djdialog1(QWidget *parent)
: QDialog(parent)
{
setupUi(this); // initialize my form <<<<<<<<<<<<<<<<<<<In the ctor.
Outside and in main is very unusual :) -
Hi
It seems you did already call it the normal place ?
djdialog1::djdialog1(QWidget *parent)
: QDialog(parent)
{
setupUi(this); // initialize my form <<<<<<<<<<<<<<<<<<<In the ctor.
Outside and in main is very unusual :) -
@mrjj The call to setupUi in main was commented-out, so it doesn't happen twice. Maybe I need to do it in main, instead of the dialog. I will have read about how to set a breakpoint in Qt4.
-
@mrjj The call to setupUi in main was commented-out, so it doesn't happen twice. Maybe I need to do it in main, instead of the dialog. I will have read about how to set a breakpoint in Qt4.
@DocDJ Sorry, but this is just completely wrong:
Ui::djdialog1 ui; // define an object named "ui" as being a djdialog1 QDialog *mydialog = new QDialog; ui.setupUi(mydialog);
You call setupUi() in the window/dialog you create. That means djdialog1 calls it in its constructor (what you're already doing). main is not the correct place to call setupUI. You really should learn Qt basics first, what you are doing now is just guessing and is wrong.
You can create a default widgets project edit the main window, add a dialog and check the generated code. -
@DocDJ Sorry, but this is just completely wrong:
Ui::djdialog1 ui; // define an object named "ui" as being a djdialog1 QDialog *mydialog = new QDialog; ui.setupUi(mydialog);
You call setupUi() in the window/dialog you create. That means djdialog1 calls it in its constructor (what you're already doing). main is not the correct place to call setupUI. You really should learn Qt basics first, what you are doing now is just guessing and is wrong.
You can create a default widgets project edit the main window, add a dialog and check the generated code.@jsulm said in program closes too soon:
Sorry, but this is just completely wrong:
Actually it's correct. I often initialize the widgets through forms without deriving. The most typical example being:
QMainWindow window; Ui::MyMainWindowForm ui; ui.setupUi(&window); window.show;
Notice that the initialized widget is a generic one (as with his code).
PS. And by the way this is commented out.
Kind regards.
-
It would appear that setupUi is not being called. Here is my main.cpp:
#include <QApplication> // following 2 lines are initially here to build the "project" //#include <QDialog> //#include "ui_djdialog1.h" // following line replaces the above 2 lines #include "djdialog1.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); /** original code before 1st qmake-qt4 my.pro Ui::djdialog1 ui; // define an object named "ui" as being a djdialog1 QDialog *mydialog = new QDialog; ui.setupUi(mydialog); */ // following line is new (after initial make) djdialog1 *mydialog = new djdialog1; mydialog->show(); return app.exec(); }
I got this from a Qt tutorial.
[Added code tags ~kshegunov]
-
@jsulm said in program closes too soon:
Sorry, but this is just completely wrong:
Actually it's correct. I often initialize the widgets through forms without deriving. The most typical example being:
QMainWindow window; Ui::MyMainWindowForm ui; ui.setupUi(&window); window.show;
Notice that the initialized widget is a generic one (as with his code).
PS. And by the way this is commented out.
Kind regards.
@kshegunov You're right - it is not wrong, but it is not how it is usually done (at least what I saw so far).
Isn't setupUi() called in the constructor already?djdialog1::djdialog1(QWidget *parent) : QDialog(parent) { setupUi(this); // initialize my form
@DocDJ "Adding Ui-> in front of answerbox causes an error." - it is ui-> not Ui->
-
@kshegunov You're right - it is not wrong, but it is not how it is usually done (at least what I saw so far).
Isn't setupUi() called in the constructor already?djdialog1::djdialog1(QWidget *parent) : QDialog(parent) { setupUi(this); // initialize my form
@DocDJ "Adding Ui-> in front of answerbox causes an error." - it is ui-> not Ui->
@jsulm said in program closes too soon:
but it is not how it is usually done
True, I'm only remarking it's a valid approach. I actually don't advise its usage for beginners.
Isn't setupUi() called in the constructor already?
No, because the object in question is of type
QDialog
. There's duplication of names - the same name is used for the form and the custom dialog, so I think this is where the confusion stems from.@DocDJ
Please provide the header file for your class as well. I have a strong suspicion you're deriving both from the dialog and the ui form.