Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to call a new window on click of a pushbutton in Qt?
Forum Updated to NodeBB v4.3 + New Features

How to call a new window on click of a pushbutton in Qt?

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 6 Posters 19.5k 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.
  • S Offline
    S Offline
    Sheenu
    wrote on last edited by
    #1

    I am using calculatorform as my main window. But I want total to be displayed in a new window and not the main window. I tried adding a push button through calculatorform.ui and call the window , but I suppose I am not writing the correct code. Could anyone please help me doing this?

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

      welcome to devnet

      When adding anything to an existing window and doing the necessary creation/compiling steps the already existing window will change.

      Apparently you want to have another window with a different layout. You need to create a new window object with all the files required (.ui, .cpp, .h) and create an instance of this window in your program.

      Did you start and go through "the step-by-step tutorials? ":https://qt-project.org/doc/qt-4.8/tutorials.html

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sheenu
        wrote on last edited by
        #3

        Yes i know that. i want to know what function should i write at main.cpp where button is present?

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

          If you like to see another window instead of the one which is used at the moment, you simply have to substitute with the name of the new window prior to compilation.

          However, if you want to change it dynamically, well, it is a bit more complicated than just adding another function to main.cpp. I would recommend to go through some of the related "examples for dialogs":https://qt-project.org/doc/qt-4.8/examples-dialogs.html . May the "extension example":https://qt-project.org/doc/qt-4.8/dialogs-extension.html helps you .

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

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wspilot
            wrote on last edited by
            #5

            Would be better if you gave some more info, like QT-C++ or QML, or both and some code.
            Please don't expect from others to dig up the example you are using (or at least give the link).
            I have an application with several dialogs and subwindows, so I might help you, but it is not clear to me what you have tried until now.

            1 Reply Last reply
            0
            • N Offline
              N Offline
              ndv472
              wrote on last edited by
              #6

              i am having main window and subwindow.
              both having different .cpp , .h and .ui file
              i want that when i push a push button then subwindow should open.
              i used show() but it will not work for me . It will show me main window as if as a new window instead of subwindow.
              what should i do please resolve this problem.
              thanks in advance ...

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andreyc
                wrote on last edited by
                #7

                ndv472 this thread is two years old.
                Could you start a new thread with your question.

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  ndv472
                  wrote on last edited by
                  #8

                  ok sir

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    joshmarshall95
                    wrote on last edited by
                    #9

                    include your form class in your mainwindow .h file
                    then declare and object of your class e.g MyClass *class
                    create function within your mainwindow.cpp
                    {
                    class = new MyClass(this)
                    MyClass->show();
                    }
                    then simply call the function on your push button

                    1 Reply Last reply
                    1

                    • Login

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