Multiple Windows Desktop application
-
Hi to everybody,
how the title describes I'm trying to program a Desktop Application with qt libraries. I use the qt designer in Visual Studio 2010, so I'm programming in c++. My problem is to set multiple windows at the same time in a way that they could interact together. For example I need a window with more pushbuttoms and clicking on them i need to activate a signal which hides the current window and shows another window. How could I do?
Thanks for the answers -
Create multiple top-level windows and connect them as required using signals and slots. If you are going to have some sort of permanent "switchboard" window then make that the one that your program's main() creates, and have it create/show/hide the others as required.
-
If i create multiple top-level windows I can't connect them using signals and slots becouse I must save them on different files .ui and in qt designer I can't connect them manually becouse signals and slots are depending on their particolar class.
How can I use the way your are suggest me with qt designer? -
-
IPC is only necessary if the windows are controlled by different processes. I doubt that is what rufy23 wants to do.
rufy23: Of course you can use signals and slots between different UIs. You just can not set them in the designer, but are free to add them from your code later.
-
bq. hides the current window and shows another window
Sorry, did I mistakenly interpreted this as independent windows? My bad.
This "link":http://doc.qt.digia.com/qt/tools-customtypesending.html might be a little different but the theory is the same, I think.
-
Thank you, I understand what you say. Now I ask another help: is there an easier and faster way to do this? I have to do an application with a lot of windows linked together and I think it is not so easy to do without the qt designer, also becouse I always used it to do everything.
-
No, it is not. Qt Designer is a great tool for designing widgets, but it is not a complete visual programming environment. You still need to write code. If you try to force everything into one single designer file, you're going to end up with a single huge class. That is not very maintainable or reusable.
-
Ok, but I can't understand just one thing. If I create a lot of classes, one for each window for example, how can I connect them in this way? I have some difficulties to create signals which are referred to different objects.
For Example I create a class for the first window and another class for the second. I have for each of the both three files (first window has: ui_firstwindow.h firstwindow.h firstwindow.cpp and the same thing for the second window). In first window there is a pushbutton called next which hides first window and shows second window. In second window there is a pushbutton called previous which hides second window and shows first window. For the next button where do I have to put the connect?I have this problem becouse I can't understand how to connect different objects. -
Define an exposed signal in your window class:
@
class Window1: public QWidget
{
...
signals:
void showOtherWindow();
};
@Connect the push button to your own hide() slot and also emit the signal:
@
Window1::Window1(QWidget *p = 0):
QWidget(p), ui(new Ui::Window1)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), SLOT(hide()));
connect(ui->pushButton, SIGNAL(clicked()), SIGNAL(showOtherWindow()));
}
@
You can connect a signal to another signal and arrival of the first will trigger emit on the second. Window2 looks the same. In your main:
@
int main(int argc, char **argv)
{
QApplication app(argc, argv);Window1 w1; Window2 w2; QObject::connect(&w1, SIGNAL(showOtherWindow()), &w2, SLOT(show())); QObject::connect(&w2, SIGNAL(showOtherWindow()), &w1, SLOT(show())); w1.show(); // only show one of them to start return app.exec();
}
@