S
S
sddvxd2018-09-02 20:05:01
Qt
sddvxd, 2018-09-02 20:05:01

Why does an Access violation occur?

Hello!
In my MyForm class, I inherit QMainWindow and pass a pointer to the parent widget to its constructor. If I try to call MyForm() with an argument in the form of a pointer to a widget, I get an Access Violation:

//forms.h

#include "ui_mainwindow.h"
#include "ui_settings.h"

class MainForm : public QMainWindow
{
    Q_OBJECT

private:
    Ui::MainWindow* mainWindow;
public:
    explicit MainForm(QWidget* pobj = 0) : QMainWindow (pobj) {
       mainWindow->setupUi(this);
    }
    Ui::MainWindow* getUiClass(){
        return mainWindow;
    }
};

//main.cpp
    QMainWindow* form = new QMainWindow;
    MainForm f1(form); //Ошибка!

If I don't specify parent object, then there is no error. Please tell me what could be the problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-09-02
@sddvxd

Ui::MainWindow* mainWindow;
mainWindow->setupUi(this);
^^^^^^^
nullptr

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question