Solved Form constructors
-
Hye,
I tried to implement a form class with 2 constructors.Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::Form) { ui->setupUi(this); } Form::Form(Qstring & tmp, QWidget *parent) : QWidget(parent), ui(new Ui::Form) { ui->setupUi(this); ui->textEdit->setText(tmp); } Form::~Form() { delete ui; } void Form::on_pushButton_clicked() { this->close(); }
I found any example with 2 constructors.
I'm certain that i lost something somewhere....I want to open this form at the beginning in the main.cpp and open it when i clicked on a button on the main form.
Ths for reading.
-
Why don't you just call the default
Form
constructor in your overloaded constructor:Form::Form(QString &tmp, QWidget *parent) : Form(parent) { ui->textEdit->setText(tmp); }
If you want to show the form, you can use the
exec
function - however, you need to change your base class to aQDialog
:Form myForm; myForm.exec();
-
If you want to present a "Widget" :
In the main.cpp:
SEView w(&IK); w.show();
If you want to trigger the widgets showing with a click, I can use signals and slots:
QPushButton* button=new QPushButton; Form* form= form("tmp",this); connect(buitton,SIGNAL(clicked()),form,SLOT(show()));
The documentation is also helpful: http://doc.qt.io/qt-5/qwidget.html#show
-
I think that the form was destroyed when the function who constructs it , was ended.
void MainWindow::on_pushButton_3_clicked() { QString Txt = "ca fonctionne"; Form viewNumber(Txt,0); viewNumber.show(); }
-
In fact, i need to pop up this window in certains conditions.
The solution to connect events together , seem to be difficult.
The automation isn't able to allow some logical purposes.for example, if good result, show a smily else show a red devil.
In my case, when the com3 has some good setting, shows the form....
I'm clear, am i?
-
Do you think it 's faithful to put the form declaration as a pointor in the Private class of MainForm.h?
-
So, it seems to workwith a private pointor in form.h.
void MainWindow::on_pushButton_3_clicked() { QString Txt = "ca fonctionne"; viewNumber= new Form(Titre); viewNumber->show(); }
-
Hi,
You are now leaking widgets each time you call that method.
What exactly do you want to do with it ? Is it a dialog ?