Problem in children windows switching
-
I wanna make 3 windows: MainWindow, profile, config, and could switch from "MainWindow" to "profile", and from "profile" to "config" using pushbottons ( the real project is an user manu, have more windows, but work like this. )
my way is: in class MainWindow, there're two private member pointers, in Profile and Config type, like this:
@
// in mainwindow.h
...
class MainWindow : public QMainWindow
{
...
private:
Ui::MainWindow *ui;
Profile *profile;
Config *config;
};
@
In MainWindow's constructor, realize the two children, and pass "this" pointer to be their parent:
@
// in MainWindow.cpp
// in MainWindow's constructor...
profile = new Profile(this);
config = new Config(this);@
and,in the corresponding slot in the MainWindow, hide the MainWindow and show the Profile window:
@
void MainWindow::on_pushButton_profile_clicked()
{
this->hide();
profile->show();
profile->exec();
this->show();
}
@
it works fine.my problem is, do now know how to jump from "Profile" window to the "Config" window, because do not know how to reach the "config" class in the "profile" class. They are all members of the MainWindow, so MainWindow know them, but I do not know how let them access each other.
I think there could be some way like this:
@
// in profile.cpp...
void Profile::on_pushButton_config_clicked( )
{
this->close();
this->parent->config->show(); /* fake code /
this->parent->config->exec(); / fake code */
}
@
the usage of "parent" is wrong,I just use this way to express my meaning。please give me some advice, thanks.
and, I appreciate for any some example code of menu,
my mail:cailei_sjtu@hotmail.com
Thanks a lot.
[edit] code wrappings added, koahnig
-
Why not add a signal to profile dialog such that when config button is pressed it emits it to a lot in main and it hides profile and shows config
-
welcome to devnet
Please use "code wrappings":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 next time. This makes your code section better readable.
-
DBoosalis:
good idea! I'll try this way.
koahnig:
Thanks for your remind!
-
another probelm met:
now I use MainWindow to control the child's switch, when child B want switch to child C, it emit a signal to the MainWindow, and the MainWindow does:
@b.hide();
c.show();
c.exec();@and when child C want to switch to child B, the MainWindow does:
@c.hide();
b.show();
b.exec();@After successfully switch from MainWindow to B, and from B to C, now the problem is, when want switch back to C from B, it directly jump to MainWindow, with warning as following:
Dialog::exec() recursive call
seems that I abused the exec() in my code.
What's the way out? thanks.