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



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



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



  • 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)


  • Lifetime Qt Champion

    Hi,

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



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



  • @alex_malyu er how would I implement it?



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



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