Regarding the navigation from one window to other



  • 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



  • 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.



  • 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



  • 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.



  • 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 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.



  • 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()
    }@



  • 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 !



  • Thanks alot. i will try the same



  • 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



  • 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



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.