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. Regarding the navigation from one window to other
Qt 6.11 is out! See what's new in the release blog

Regarding the navigation from one window to other

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 10.3k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hai everybody, I am new to Qt. I want to know how to move from one window to other by a click. The problem statement is given below:
    I am having a table with 12 rows and 3 columns and nearby i have put a pushbutton. By selecting any one of the row and clicking the pushbutton i have to go to a new window. I am doing every thing without user interface.
    I have created the table and push button using program.
    Can anybody help me

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      You mean like when you push that button, another window will show up?

      If that's the case, just create a window, then hide it at the start. Then connect the signal click button with a funtion which will show the hidden window.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thanks alot for the reply. I need to see the window wen the push button is clicked. Actually i have written the code in a different way which will give only a message box. I am enclosing the code along with this post. Can u please tell me how to modify the same . I am having one header file named mainwindow.h and one .cpp file mainwindow.cpp and a main file

        Mainwindow.h file

        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H
        #include <QtGui/QMainWindow>
        class MainWindow : public QMainWindow
        {
        Q_OBJECT

        public:
        MainWindow(QWidget *parent = 0);
        ~MainWindow();
        private slots:
        void on_pushButton_clicked();
        };

        Mainwindow.cpp

        #include "mainwindow.h"
        #include <QtGui>
        #include <QTableWidget>
        #include <QPushButton>
        MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        {
        QTableWidget *tablewidget = new QTableWidget(this);
        int column=3,row=12;
        tablewidget->setColumnCount(column);
        tablewidget->setRowCount(row);
        tablewidget->setItem(0, 0, new QTableWidgetItem("UP"));
        tablewidget->setItem(0, 1, new QTableWidgetItem("EAST"));
        tablewidget->setItem(0, 2, new QTableWidgetItem("NORTH"));
        tablewidget->setItem(1, 0, new QTableWidgetItem("UP"));
        tablewidget->setItem(1, 1, new QTableWidgetItem("WEST"));
        tablewidget->setItem(1, 2, new QTableWidgetItem("SOUTH"));
        tablewidget->setItem(2, 0, new QTableWidgetItem("DOWN"));
        tablewidget->setItem(2, 1, new QTableWidgetItem("WEST"));
        tablewidget->setItem(2, 2, new QTableWidgetItem("NORTH"));
        tablewidget->move(350,300);
        tablewidget->resize(330,385);
        QPushButton *button= new QPushButton(this);
        button->move(1000,300);
        button->setText("OK");
        connect(button,SIGNAL(clicked()),this,SLOT(on_pushButton_clicked()));
        }
        MainWindow::~MainWindow()
        {
        }
        void MainWindow::on_pushButton_clicked()
        {
        QMessageBox :: information(this,"title here","heloo");
        }

        Main.cpp

        #include <QtGui/QApplication>
        #include "mainwindow.h"
        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();

        return a.exec&#40;&#41;;
        

        }

        Also can please explain me the method of creating the new windows.
        Expecting your early reply

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Code_ReaQtor
          wrote on last edited by
          #4

          Create a new class that inherits QMainWindow.

          for example:

          @
          #include <QMainWindow>

          class YourWindow : public QMainWindow
          {
          Q_OBJECT
          public:
          YourWindow(QWidget *parent = 0);
          ~YourWindow();
          //add other functions you want here
          };@

          If you want the window, "parentless"... you may copy what was done in main.cpp into your MainWindow.cpp:

          @YourWindow w;
          w.show();@

          If not:

          @YourWindow *w=new YourWindow(this);
          w->exec();@

          Note the difference between show() and exec(). You may read the QWidget documentation about these 2 functions since QMainWindow inherited QWidget.

          Please visit my open-source projects at https://github.com/Code-ReaQtor.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            So basically you need to display another window when you click on push button [if I have understood correctly].
            Dialog window is best way. You can use QDialog class.

            @void MainWindow::on_pushButton_clicked()
            {
            QDialog *dialog = new QDialog();
            dialog->setModal(true);
            dialog->exec();
            }@

            You can have separate class inherited from QDialog if you wish any design in your dialog window.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Code_ReaQtor
              wrote on last edited by
              #6

              [quote author="kirangps" date="1352271346"]So basically you need to display another window when you click on push button [if I have understood correctly].
              Dialog window is best way. You can use QDialog class.

              @void MainWindow::on_pushButton_clicked()
              {
              QDialog *dialog = new QDialog();
              dialog->setModal(true);
              dialog->exec();
              }@

              You can have separate class inherited from QDialog if you wish any design in your dialog window.[/quote]

              Exactly.

              But the problem with QDialog was that it blocks all user interaction to your "Main GUI" until it is closed. If you want a "non-blocking" window, use QWidget... but your choice depends on what you need.

              Please visit my open-source projects at https://github.com/Code-ReaQtor.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                bq. But the problem with QDialog was that it blocks all user interaction to your “Main GUI” until it is closed. If you want a “non-blocking” window, use QWidget… but your choice depends on what you need.

                That's correct, dialog window with above code blocks all user interaction with main window as it is a Modal dialog. You can use Non Modal dialog, like,

                @void MainWindow::on_pushButton_clicked()
                {
                QDialog *dialog = new QDialog();
                dialog->setModal(false); //make it true for Modal dialog
                dialog->show(); // and use show() instead of exec()
                }@

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  issam
                  wrote on last edited by
                  #8

                  Hi, I had the some problem last year in a small project, an application that implement the AHP process.
                  So I used the QWizard class.

                  So, If QWizard fits your application use it, it is simple !

                  http://www.iissam.com/

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    Thanks alot. i will try the same

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #10

                      hai everybody , thanks for your help. Now i am able to navigate from one window to other.
                      I need to add some widgets in the navigated window. But when i am adding it is not seen in the new window. Can anybody help in this. Advance thanks to all

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #11

                        sorry for the late reply. I am attaching the code. as the code is having more .cpp and .h files, i am attaching only the page for which the clarification is needed. once again i will tell the aim of the program is listed below:
                        (1) i want to access the serially transmitted datas from another computer
                        (2) As soon as the datas are received the same should be displyed in a oscilloscope.

                        Problem to be solved:
                        (1) I am able to display one window and able to collect the data through serial port. I have placed a push button in that window. wen the push button is clicked i want to generate a new window in which the qwt oscilloscope window has to be displayed.
                        (2) I will show the line of code which i have written in this program for the same

                        connect(ui->openCloseButton, SIGNAL), SLOT));

                        after the same i have called the osci() function as the one below. void MainWindow::osci() { QMainWindow *osci = new QMainWindow(this); osci->show(); }

                        Now wen i am clicking a new window is displaying . My question is how to add the components into that new window. or how to include the oscilloscope program of qwt to it .
                        I was not able to post the entire code here as it is showing exceeding of 6000 characters
                        I will really gratefull if anybody can give the solution for the one above.
                        I am conveying my advance thanks to all.

                        expecting a postive reply

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          Code_ReaQtor
                          wrote on last edited by
                          #12

                          have you tried reading through the Qwt examples? I relied on their examples when I am developing an application that needs graph.

                          Please visit my open-source projects at https://github.com/Code-ReaQtor.

                          1 Reply Last reply
                          0
                          • ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #13

                            i have read the Qwt examples . but there is no proper guidance

                            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