QMdiArea problem [SOLVED]



  • Hey,
    i have created a widget that generates a custom grid. I wan to have a window that when i click "New Grid" a new grid must be opend. I want to have the ability to open multiple grid. So as i searched i found the QMdiArea to be a good solution.
    The code of MainWindow.h is
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QMdiArea>
    #include <QToolBar>
    #include <QAction>

    class VDatagridView;

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private slots:
    void createVDataGridView();

    private:
    QMdiArea *mdiArea;
    QToolBar *toolbar;
    QAction *newGridAction;
    QAction *clearAction;
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H
    @

    and the MainWindows.cpp is
    @#include "MainWindow.h"
    #include "ui_MainWindow.h"
    #include "VDatagridView.h"
    #include <QSplitter>
    #include <iostream>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    mdiArea = new QMdiArea;
    setCentralWidget(mdiArea);
    toolbar = addToolBar(tr("VDataGridView ToolBar"));
    toolbar->addAction(tr("New Grid"));
    toolbar->addAction(tr("Clear"));
    newGridAction = new QAction(tr("New Grid"), this);
    clearAction = new QAction(tr("Clear"), this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::createVDataGridView()
    {
    VDatagridView *form = new VDatagridView(this);
    mdiArea->addSubWindow(form);
    form->show();
    }
    @

    What is the problem in my code? Becuase when i press "New Grid" my widget don'n open.

    Thanks!


  • Moderators

    you create 2 actions

    you don't connect any of these 2 actions to your slot which does the work you want

    Try this:
    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    mdiArea = new QMdiArea;
    setCentralWidget(mdiArea);
    toolbar = addToolBar(tr("VDataGridView ToolBar"));
    newGridAction = toolbar->addAction(tr("New Grid"));
    connect( newGridAction, SIGNAL(triggered()), this, SLOT(createVDataGridView()) );
    clearAction = toolbar->addAction(tr("Clear"));
    //connect( clearAction, SIGNAL(triggered()), this, SLOT(...) );
    }
    @



  • unfortunately nothing changed


  • Moderators

    i can't believe that. The code you've posted with my changes merged into it works for me...



  • you r right. Thanks a lot!


Log in to reply
 

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