Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem in children windows switching
Forum Updated to NodeBB v4.3 + New Features

Problem in children windows switching

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leilc
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DBoosalis
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        welcome to devnet

        Please use "code wrappings":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 next time. This makes your code section better readable.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leilc
          wrote on last edited by
          #4

          DBoosalis:

          good idea! I'll try this way.
          

          koahnig:

          Thanks for your remind!
          
          1 Reply Last reply
          0
          • L Offline
            L Offline
            leilc
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved