Calling the mainwindow methods from the dialog.



  • I am trying to get the methods working for the mainwindow in the dialog.cpp. typing tt-> does not display the mainwindow methods when i type it at the dialog.cpp. the error i am getting is dialog.cpp:10: error: no match for 'operator=' in '((Dialog)this)->Dialog::tt = (operator new(28u), (<statement>, ((MainWindow*)<anonymous>)))'

    note that if i change line 10 in the dialog to MainWindow *tt = new MainWindow; then the program does not load up and MainWindow *tt; crashes the program. MainWindow tt; does not load up the program ether.

    dialog.h
    @#ifndef DIALOG_H
    #define DIALOG_H

    #include <QDialog>

    class MainWindow;
    namespace Ui {
    class Dialog;
    }

    class Dialog : public QDialog
    {
    Q_OBJECT

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

    private:
    Ui::Dialog *ui;
    MainWindow *tt;
    };

    #endif // DIALOG_H@

    mainwindow.h
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    class Dialog;
    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

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

    private:
    Ui::MainWindow *ui;
    Dialog *uu;
    };

    #endif // MAINWINDOW_H@

    dialog.cpp
    @#include "dialog.h"
    #include "ui_dialog.h"
    #include "mainwindow.h"

    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);
    *tt = new MainWindow;
    }

    Dialog::~Dialog()
    {
    delete ui;
    }@

    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "dialog.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    Dialog *uu = new Dialog(this);
    }

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



  • @
    MainWindow *tt;
    @
    so,
    @
    *tt = new MainWindow;
    @
    is always wrong.

    The following code has problem too.
    @
    Dialog *uu;
    @
    @
    Dialog *uu = new Dialog(this);
    @

    And the most important thing is that there are some design issues.

    In Dialog's constructor, an MainWindow object created, in MainWindow's constrcutor, the second Dialog object is created, in the second Dialog's constructor, another MainWindow object is created, in the ...


  • Moderators

    If you have a MainWindow and you create another MainWindow inside of Dialog, they do not refer to the same object.

    If you want to communicate back and forth between your Dialog and MainWindow, perhaps you should use signals and slots.


Log in to reply
 

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