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. Calling the mainwindow methods from the dialog.
QtWS25 Last Chance

Calling the mainwindow methods from the dialog.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.1k Views
  • 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    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;
    }@

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        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.

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        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