Results 1 to 2 of 2

Thread: Error when building example from C++ GUI Progamming with Qt4

  1. #1
    Join Date
    Mar 2015
    Posts
    8
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Error when building example from C++ GUI Progamming with Qt4

    Hi everyone, I have just downloaded QT 5.4.1 for a couple of days. Because there is no book for Qt 5, I use the book named "C++ GUI Programming with Qt 4". I'm learning about QDialog and Qt Designer, and I copied the source code from that book to run on my Qt. However, it didn't work but announced "The inferior stopped because it triggered an exception.". I don't know why. Here are he source code:
    The header:
    Qt Code:
    1. #ifndef GOTOCELLDIALOG_H
    2. #define GOTOCELLDIALOG_H
    3.  
    4. #include <QDialog>
    5. #include "ui_gotocelldialog.h"
    6.  
    7. namespace Ui
    8. {
    9. class GoToCellDialog;
    10. }
    11.  
    12. class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
    13. {
    14. Q_OBJECT
    15. public:
    16. explicit GoToCellDialog(QWidget *parent = 0);
    17. ~GoToCellDialog();
    18. private slots:
    19. void on_lineEdit_textChanged();
    20. private:
    21. Ui::GoToCellDialog *ui;
    22. };
    23.  
    24. #endif // GOTOCELLDIALOG_H
    To copy to clipboard, switch view to plain text mode 

    The implementation of the class:
    Qt Code:
    1. #include "gotocelldialog.h"
    2.  
    3. GoToCellDialog::GoToCellDialog(QWidget *parent)
    4. :QDialog(parent),
    5. ui(new Ui::GoToCellDialog)
    6. {
    7. ui->setupUi(this);
    8.  
    9. QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
    10. lineEdit->setValidator(new QRegExpValidator(regExp, this));
    11.  
    12. connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    13. connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
    14. }
    15.  
    16. GoToCellDialog::~GoToCellDialog()
    17. {
    18. delete ui;
    19. }
    20.  
    21. void GoToCellDialog::on_lineEdit_textChanged()
    22. {
    23. okButton->setEnabled(lineEdit->hasAcceptableInput());
    24. }
    To copy to clipboard, switch view to plain text mode 

    The main source code:
    Qt Code:
    1. #include "gotocelldialog.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. GoToCellDialog w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    There's also a .ui file that contains a label, lineEdit, okButton and cancelButton. Please help me solve this error. Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Error when building example from C++ GUI Progamming with Qt4

    First, you don't need to inherit from Ui::GoToCellDialog.
    Second, all widgets of the designer form are addressed through the ui pointter
    Qt Code:
    1. connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    To copy to clipboard, switch view to plain text mode 

    You were accessing the inherited member cancelButton which was not initialized

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Rabbitl96l (28th March 2015)

Similar Threads

  1. [Qt 5.2.1] Building sql DB2 driver error
    By Hypnotic92 in forum Installation and Deployment
    Replies: 1
    Last Post: 27th December 2014, 11:25
  2. Qt 4.8.4 Webkit error while building
    By sonulohani in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2013, 10:01
  3. Error After building in device
    By rahulgogoi in forum Qt Programming
    Replies: 0
    Last Post: 7th June 2011, 07:54
  4. Error when building Qt4 on Mac OS X
    By DragonLance156156 in forum Installation and Deployment
    Replies: 11
    Last Post: 17th February 2009, 17:29
  5. Building qt error
    By as001622 in forum Installation and Deployment
    Replies: 1
    Last Post: 20th June 2008, 09:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.