Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Opening a new window form crashes.
Qt 6.11 is out! See what's new in the release blog

Opening a new window form crashes.

Scheduled Pinned Locked Moved Qt Creator and other tools
5 Posts 3 Posters 3.4k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fatihAyt3kin
    wrote on last edited by
    #1

    Hi everyone,

    I am having a problem with opening a new form by clicking a button. Whenever I push on the button which will open a new form, the program crashes and gives me the error 1073741819. I searched the web and found out that it's a access violation. I defined a pointer mProgram in private form of mainwindow.h and tried to show that pointer in void pushbutton. I don't know what i am doing wrong..

    This is my mainwindow.cpp
    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "mainprogram.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

    ui->setupUi(this);
    

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

    void MainWindow::on_pushButton_clicked()
    {
    mProgram->show();

    }
    @

    This is my mainprogram.cpp

    @
    #include "mainprogram.h"
    #include "ui_mainprogram.h"
    #include "QApplication"

    mainProgram::mainProgram(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::mainProgram)
    {
    ui->setupUi(this);
    }

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

    This is my mainwindow.h

    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include "mainprogram.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void on_MainWindow_iconSizeChanged(const QSize &iconSize);

    private slots:

    void on_pushButton_clicked();
    

    private:
    Ui::MainWindow *ui;
    mainProgram *mProgram;
    };

    #endif // MAINWINDOW_H
    @

    and this is my mainprogram.h

    @
    #ifndef MAINPROGRAM_H
    #define MAINPROGRAM_H

    #include <QMainWindow>
    #include <QApplication>

    namespace Ui {
    class mainProgram;
    }

    class mainProgram : public QMainWindow
    {
    Q_OBJECT

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

    private:
    Ui::mainProgram *ui;

    };

    #endif // MAINPROGRAM_H

    @

    I am just trying to open a new form named "mainprogram" from mainwindow. I am new QT and trying to learn some basics and would appreciate any help.. Thank you

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fransis
      wrote on last edited by
      #2

      Hi!
      can you try put this into the mainwindows.cpp constructor?

      mProgram = new mainProgram ();

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        Or better:
        @mProgram = new mainProgram (this);@

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fatihAyt3kin
          wrote on last edited by
          #4

          Thank you for the replies, but I tired them before and got this error, and honestly couldn't find any piece of solution to this. any suggestions?

          error LNK2019: unresolved external symbol "public: __thiscall mainProgram::mainProgram(class QWidget *)" (??0mainProgram@@QAE@PAVQWidget@@@Z) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)

          I

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fransis
            wrote on last edited by
            #5

            can you try clean all and then build again? I copy your sorce code and build and run fine. I copied your code and build the code and it run fine on my IDE.

            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