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. How to call ui->show(); from other file
Forum Updated to NodeBB v4.3 + New Features

How to call ui->show(); from other file

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.6k Views 3 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.
  • Q Offline
    Q Offline
    Q139
    wrote on last edited by
    #1

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

     QSurfaceFormat format;
     //antializing samples
     format.setSamples(16);
     TriangleWindow window;
     window.setFormat(format);
     window.resize(900, 700);
     window.setAnimating(true);
     window.show();  //gl
    
     MainWin m_win;
     m_win.show();       //ui
    
     timer_class tim;
     tim.start_play_timer();
    
    return a.exec();
    

    }

    How to call ui->show(); from other file?

    Cannot declare extern and place MainWin m_win before main() it crashes app.
    Also would be good if QSurfaceFormat format; acessible by other files.

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by JohanSolo
      #2

      I guess the ui->show() you're referring to is the one from the designer part of your MainWin class. Why don't you add a method in MainWin which internally callsui->show()?

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Q139
        wrote on last edited by
        #3

        Can you please describe in more detail , my programming vocabulary not very good.

        1 Reply Last reply
        0
        • JohanSoloJ Offline
          JohanSoloJ Offline
          JohanSolo
          wrote on last edited by
          #4

          Well, your question is not so clear as well. I'll try again.

          I guess the ui you're talking about is declared in the MainWin header fil e. Then what I told you is IF you need to be able to call ui->show, you could add a method in MainWin class, which would internally call ui->show. However, I don't think this is usefull, as calling MainWin::show() calls show for the ui component.

          I have no clue about which QSurfaceFormat instance you're talking about. I don't have any crystal ball, therefore it's hard to tell.

          `They did not know it was impossible, so they did it.'
          -- Mark Twain

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Q139
            wrote on last edited by Q139
            #5

            Very sorry, i was not aware that you are not having big crystal ball.
            Would like to be able to call TriangleWindow and mainwin from eachother to respawn closed window.

            mrjjM 1 Reply Last reply
            0
            • Q Q139

              Very sorry, i was not aware that you are not having big crystal ball.
              Would like to be able to call TriangleWindow and mainwin from eachother to respawn closed window.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Q139
              Hi your idea with extern should be able to work.
              Just use pointers and it will work.

              in "TriangleWindow.h"
              have
              extern TriangleWindow *MyTW;
              and have it defined in the .cpp

              and then in main
              do
              MyTW=new TriangleWindow();
              Then in other file , say mainwindow you can include
              TriangleWindow .h and have access via
              MYTW;
              This is of course global variables and might
              not be the most elegant way of handling it.

              regarding
              QSurfaceFormat format;
              This only lives in main and you must move it as only main can see it.

              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