it can be done, (and is done most of times this way), you can create a signal of program class (instead of button signal) and connect to win1 class objects
it can be done, (and is done most of times this way), you can create a signal of program class (instead of button signal) and connect to win1 class objects
You mean creating a signal for something like a tab? How to do that? :s
Thanks
here is an example
Qt Code:
//program.h #include <QtGui> #include "ui_program.h" class wnd1; { Q_OBJECT; public: signals: void openButtonClicked(void); private: Ui::program * ui; wnd1 * w1; }; //program.cpp #include "program.h" #include "window1.h" ui(new Ui::program()), w1(new wnd1(this)) { ui->setupUi(this); connect(this, SIGNAL(openButtonClicked()), w1, SLOT(test())); } program::~program() { delete ui; } //window1.h #include <QtGui> { Q_OBJECT; public: public slots: void test(void); }; //window1.cpp #include "window1.h" { ; } void wnd1::test(void) { ;//do something }To copy to clipboard, switch view to plain text mode
I don't think you got. What I understood from this quoted post was that if I had a tab widget, I could connect example: tab1 to wnd1(window1.cpp), tab2 to wnd2(window2.cpp); and then every control from the connected tab would signal the connected object, but forget that. I just wanted to do something like:
Qt Code:
//program.cpp ui(new Ui::program) { ui->setupUi(this); wnd1 w1; w1.Initialize(); } //window1.cpp void wnd1::Initialize() { connect(ui->button1, SIGNAL(clicked()), this, SLOT(test1())); connect(ui->button2, SIGNAL(clicked()), this, SLOT(tes2t())); connect(ui->button3, SIGNAL(clicked()), this, SLOT(test3())); connect(ui->button4, SIGNAL(clicked()), this, SLOT(test4())); connect(ui->button5, SIGNAL(clicked()), this, SLOT(test5())); // but i don't know how to get a handle the buttons in window1.cpp since 'ui' is from program.cpp }To copy to clipboard, switch view to plain text mode
Sorry for the misunderstanding.
Last edited by lucastonon; 14th July 2011 at 05:04.
I was trying to tell you that, make the connections in program.cpp not is window1.cpp, move the connect statements to program class ctor (this is a standard way doing).// but i don't know how to get a handle the buttons in window1.cpp since 'ui' is from program.cpp
In program.cpp you will have handles to buttons, and you also know that wnd1 class has an public slot testx()
Ok I'll make the connections at program.cpp. But in case in window1.cpp I need to get the text of a text edit I would need to have ui->textEdit1 in window1.cpp, but I can only use that in program.cpp
You are still getting it worng, do not create wnd1 variable in program.cpp constructor. (it will not work) also, refer to my post (Post #4) for example to create objects
I can see you are complicating your situation, Please review your code again.
Problem: You are tyring to create a object of program class with in a slot connected to a signal emitted by program class it self, why do you need to do it this wa? I am not sure of your requrements, but you don't want this.
Either create program class object in wnd1 class or create wnd1 class object in program class, but don't do both![]()
Bookmarks