I don't know if you understand the problem. I understood the Bong's problem. His has 2 ui files. One ui is its main file. The other ui is specially designed for the QDialog. How to connect the other.ui file with the push Button???
I don't know if you understand the problem. I understood the Bong's problem. His has 2 ui files. One ui is its main file. The other ui is specially designed for the QDialog. How to connect the other.ui file with the push Button???
I understood his problem, and the solution is in front of you:
Qt Code:
#include "example.h" #include "ui_example.h" #include "what_ever_dialog_class_with_ui.h" //include the header file ui(new Ui::example) { ui->setupUi(this); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked())); //connect... the signal with slot ... } example::~example() { delete ui; } void example::on_pushButton_clicked() { //use the other class to instantiate the QDialog or the QDialog derived class (with or without ui) what_ever_dialog_class_with_ui *gamatos = new what_ever_dialog_class_with_ui(this); //you need to pass 'this' as parent so that you don't get a memory leak gamatos->show(); //you show the dialog } { switch (e->type()) { ui->retranslateUi(this); break; default: break; } }To copy to clipboard, switch view to plain text mode
I cannot understand what should i change on what_ever_dialog_class_with_ui ? look what i have done..
Qt Code:
#include "example.h" #include "ui_example.h" #include "hi.h" //include the header file ui(new Ui::example) { ui->setupUi(this); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked())); //connect... the signal with slot ... } example::~example() { delete ui; } void example::on_pushButton_clicked() { //use the other class to instantiate the QDialog or the QDialog derived class (with or without ui) hi.h *gamatos = new QDialog(this); //you need to pass 'this' as parent so that you don't get a memory leak gamatos->show(); //you show the dialog } { switch (e->type()) { ui->retranslateUi(this); break; default: break; } }To copy to clipboard, switch view to plain text mode
Qt Code:
#include "example.h" #include "ui_example.h" #include "hi.h" //include the header file ui(new Ui::example) { ui->setupUi(this); // note that the declaration of pointer can be done only once connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked())); //connect... the signal with slot ... } example::~example() { delete ui; } void example::on_pushButton_clicked() { //use the other class to instantiate the QDialog or the QDialog derived class (with or without ui) hi *gamatos = new hi(this); //this is valid if the class name is "hi"... replace that with your class name //you need to pass 'this' as parent so that you don't get a memory leak gamatos->show(); //you show the dialog } { switch (e->type()) { ui->retranslateUi(this); break; default: break; } }To copy to clipboard, switch view to plain text mode
NOTE: the code changed a bit... i corrected in the previous post, but you already copied... you can't declare the pointer twice (you don't declare it in the constructor, only in the slot)
Ok i founded it.. .But know two Qdialogs are been shown :P
Qt Code:
#include "example.h" #include "ui_example.h" #include "hi.h" //include the header file ui(new Ui::example) { ui->setupUi(this); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked())); //connect... the signal with slot ... } example::~example() { delete ui; } void example::on_pushButton_clicked() { //use the other class to instantiate the QDialog or the QDialog derived class (with or without ui) hi *gamatos = new hi(this); //you need to pass 'this' as parent so that you don't get a memory leak gamatos->show(); //you show the dialog } { switch (e->type()) { ui->retranslateUi(this); break; default: break; } }To copy to clipboard, switch view to plain text mode
See the constructor... and the edits of my previous posts... you initialize the second dialog twice (create two dialogs... with two pointers that have the same name...)
Or, maybe the name of the slot match the autoconnect rules (i gave you a link in a previous post)
You can rename the slot: something like
Qt Code:
void example::openDialog() //and connect with this slot name { //use the other class to instantiate the QDialog or the QDialog derived class (with or without ui) hi *gamatos = new hi(this); //you need to pass 'this' as parent so that you don't get a memory leak gamatos->show(); //you show the dialog }To copy to clipboard, switch view to plain text mode
Or don't connect manually and let autoconnect do the connection
Last edited by Zlatomir; 17th August 2010 at 19:59. Reason: i forgot to rename the slot
Ok it works... Many thanks.. I need it..![]()
Bookmarks