This doenot work!!!Qt Code:
void example::on_pushButton_clicked() { connect(ui->pushButton, SIGNAL(clicked()), hi, SLOT(gamatos->show())); }To copy to clipboard, switch view to plain text mode![]()
This doenot work!!!Qt Code:
void example::on_pushButton_clicked() { connect(ui->pushButton, SIGNAL(clicked()), hi, SLOT(gamatos->show())); }To copy to clipboard, switch view to plain text mode![]()
Of course it doesn't.You never make a connection in the slot that it is supposed to call.
edit:
Qt Code:
void example::on_pushButton_clicked() { connect(ui->pushButton, SIGNAL(clicked()), hi, SLOT(gamatos->show())); }To copy to clipboard, switch view to plain text mode
should be something along the lines of
Qt Code:
yourClass::yourConstructor(...) : yourParent() { ... connect(ui->pushButton, SIGNAL(clicked()), hi, SLOT(on_pushButton_clicked()); ... } void example::on_pushButton_clicked() { ... gamatos->exec(); }To copy to clipboard, switch view to plain text mode
You *really* need to read and re-read the signals and slots documentation very carefully until you understand it. A slot isn't a statement, it's a function name, and the connection must be established outside of the slot otherwise the slot *cannot* be called!
Last edited by Urthas; 17th August 2010 at 19:11.
You don't connect in the slot...
Qt Code:
void example::on_pushButton_clicked() { gamatos->show(); //you show the dialog }To copy to clipboard, switch view to plain text mode
Now the connect "stuff" if you create slots by the autoconnect (in the end of that article) rules you don't need to manually connect (the autoconnect does the connection for you)
Else (and i really recommend this method) you do the connection in the class constructor, something like:
Qt Code:
example::example // : parameter passing... {//... connect(ui->NameOfButton, SIGNAL (clicked()), this, SLOT(on_pushButton_clicked())); //... rest of the constructor code }To copy to clipboard, switch view to plain text mode
See this... It still doesn't work ..
Qt Code:
#include "example.h" #include "ui_example.h" #include <QDialog> ui(new Ui::example) { ui->setupUi(this); connect(ui->pushButton, SIGNAL(clicked()), hi.ui, SLOT(gamatos())); } example::~example() { delete ui; } { switch (e->type()) { ui->retranslateUi(this); break; default: break; } } void example::on_pushButton_clicked() { connect(ui->pushButton, SIGNAL (clicked()), this, SLOT(on_pushButton_clicked())); }To copy to clipboard, switch view to plain text mode
And where is the gamatos() method, exactly? Stop thrashing. Read your error messages! Look at the code that has been handed to you...
Qt Code:
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));To copy to clipboard, switch view to plain text mode
That 'this' is a pointer to the object itself (the main window in your case) and this has the slot that will create and show the dialog (on_pushButton_clicked() in your case )
LE: the slot should be:
Qt Code:
void example::on_pushButton_clicked() { gamatos->show(); //you show the dialog }To copy to clipboard, switch view to plain text mode
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