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. When ever I run exec() on a Dialog my Application Crashes.
QtWS25 Last Chance

When ever I run exec() on a Dialog my Application Crashes.

Scheduled Pinned Locked Moved General and Desktop
dialogexe crashedcrashescrashdialog crash
7 Posts 3 Posters 4.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.
  • C Offline
    C Offline
    Coloriez
    wrote on 30 Aug 2015, 23:21 last edited by
    #1

    When ever I run exec on a dialog my application crashes
    here's the code:
    void MainWindow::on_actionHelp_triggered()
    {
    HelpDialog * hDialog;
    hDialog->exec();
    }

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on 30 Aug 2015, 23:37 last edited by alex_malyu
      #2

      All you did - declared a pointer to HelpDialog class.
      Then you dereference invalid pointer, and your application exits.

      you need create an object either on the stack:

      HelpDialog hDialog;
      hDialog. exec();

      (preferrable since you have modal dialog and seems is not going to use it outside of the function.)

      or on the heap:

      HelpDialog * hDialog = new HelpDialog(this);
      hDialog->exec();

      delete hDialog;

      Also I do not think programming with Qt is a good way to start learning C++.
      At least it is not the easiest.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Coloriez
        wrote on 31 Aug 2015, 00:05 last edited by
        #3

        err now I get these errors:
        mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl HelpDialog::HelpDialog(class QWidget *)" (??0HelpDialog@@QEAA@PEAVQWidget@@@Z) referenced in function "private: void __cdecl MainWindow::on_actionHelp_triggered(void)" (?on_actionHelp_triggered@MainWindow@@AEAAXXZ)

        mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __cdecl HelpDialog::~HelpDialog(void)" (??1HelpDialog@@UEAA@XZ) referenced in function "private: void __cdecl MainWindow::on_actionHelp_triggered(void)" (?on_actionHelp_triggered@MainWindow@@AEAAXXZ)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 31 Aug 2015, 21:54 last edited by
          #4

          Hi,

          Maybe a silly question but: Did your properly implement both these functions ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alex_malyu
            wrote on 1 Sept 2015, 01:05 last edited by
            #5

            unresolved external symbol "public: __cdecl HelpDialog::HelpDialog(class QWidget *)" (??0HelpDialog@@QEAA@PEAVQWidget@@@Z) referenced in function "private: void __cdecl

            Mostly likely means HelpDialog::HelpDialog(class QWidget *)
            was declared, but not implemented.

            C 1 Reply Last reply 1 Sept 2015, 23:38
            0
            • A alex_malyu
              1 Sept 2015, 01:05

              unresolved external symbol "public: __cdecl HelpDialog::HelpDialog(class QWidget *)" (??0HelpDialog@@QEAA@PEAVQWidget@@@Z) referenced in function "private: void __cdecl

              Mostly likely means HelpDialog::HelpDialog(class QWidget *)
              was declared, but not implemented.

              C Offline
              C Offline
              Coloriez
              wrote on 1 Sept 2015, 23:38 last edited by
              #6

              @alex_malyu er how would I implement it?

              A 1 Reply Last reply 2 Sept 2015, 02:28
              0
              • C Coloriez
                1 Sept 2015, 23:38

                @alex_malyu er how would I implement it?

                A Offline
                A Offline
                alex_malyu
                wrote on 2 Sept 2015, 02:28 last edited by
                #7

                @Coloriez

                In header file you probably have:

                class HelpDialog : public QWidget
                {
                Q_OBJECT

                public:
                HelpDialog(QWidget *parent); // this is declaration of the constructor
                ~HelpDialog();
                ....
                ///

                Every function declared and called implicitly or explicitly needs to be implemented.
                Implementation usually is either provided at the same it was declared at or in cpp file,

                For example
                You could replace HelpDialog(QWidget *parent);
                with
                HelpDialog(QWidget *parent) {};

                This would add implementation which does nothing.

                But this would be a bad idea in this case.
                You probably would want constructor which at least initialize parent. For example you could add in cpp file instead:

                HelpDialog::HelpDialog(QWidget *parent)
                :QWidget( parent )
                {
                };

                I highly recommend re-read C++ book until you understand at least the basics or search for c++ novice forum. Your questions have nothing to do with Qt yet. This is not an offence. But I doubt you will be getting help you need here due to specialization of this forum.

                1 Reply Last reply
                0

                1/7

                30 Aug 2015, 23:21

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved