The book sample code is compiling but crashing after execution in my MACBook Pro OSX 10.8.5



  • Hi,
    I am studying Qt features and I followed chapter 2 examples of "C++ GUI Programming with Qt 4 se os J.B and M.Summerfield"

    I exactly followed all the steps and instructions from page 31 to 38.
    I designed the dialog in the Qt Designer environment
    The code compiles without any error but as soon as I run the executable in my mac machine the system closes
    the application and shows me following error (trimmed version) (Sorry I do not know how to attach files with the post):

    Exception Type: EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008

    0 QtWidgets 0x0000000100077c54 QWidget::layout() const + 4
    1 com.yourcompany.RapidDialogDesign 0x000000010000387e SortDialog::SortDialog(QWidget*) + 174 (sortdialog.cpp:16)
    2 com.yourcompany.RapidDialogDesign 0x00000001000037bd SortDialog::SortDialog(QWidget*) + 29 (sortdialog.cpp:20)
    3 com.yourcompany.RapidDialogDesign 0x0000000100003659 main + 89 (main.cpp:7)
    4 com.yourcompany.RapidDialogDesign 0x00000001000035f4 start + 52
    _

    I have attached all the project files in order to find which part of the code or UI is wrong

    and following is my main.cpp

    @#include "sortdialog.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    SortDialog *dialog=new SortDialog;
    dialog->setColumnRange('C','F');
    dialog->show();
    return app.exec();
    }
    @

    and following is sortdialog.cpp

    @#include<QtGui>
    #include "sortdialog.h"

    SortDialog::SortDialog(QWidget *parent) :
    QDialog(parent)
    {

    setupUi(this);
    secondaryGroupBox->hide();  
    tertiaryGroupBox->hide();
    // Calling QLayout
    layout()->setSizeConstraint(QLayout::SetFixedSize);
    setColumnRange('A','Z');    
    

    }

    // Our useful method
    void SortDialog::setColumnRange(QChar first, QChar last){
    primaryColumnCombo->clear();
    secondaryColumnCombo->clear();
    tertiaryColumnCombo->clear();

    secondaryColumnCombo->addItem(tr("None"));
    tertiaryColumnCombo->addItem(tr("None"));
    // Related to streches of the spacer
    primaryColumnCombo->setMinimumSize(secondaryColumnCombo->sizeHint());
    
    QChar ch=first;
    while(ch <= last)   
    {
        primaryColumnCombo->addItem(QString(ch));
        secondaryColumnCombo->addItem(QString(ch));
        tertiaryColumnCombo->addItem(QString(ch));
        ch=ch.unicode()+1;  //Nice addtion
    }
    

    }

    SortDialog::~SortDialog()
    {
    }
    @

    and following is sortdialog.h

    @#ifndef SORTDIALOG_H
    #define SORTDIALOG_H

    #include <QDialog>
    #include "ui_sortdialog.h"
    // Book code

    class SortDialog : public QDialog , public Ui::SortDialog
    {
    Q_OBJECT

    public:
    SortDialog(QWidget *parent = 0);
    // Extra merged code:
    void setColumnRange(QChar first,QChar last);
    ~SortDialog();
    };

    #endif // SORTDIALOG_H@

    and following is my project file RapidDialogDesign.pro

    @QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = RapidDialogDesign
    TEMPLATE = app

    SOURCES += main.cpp
    sortdialog.cpp

    HEADERS +=
    sortdialog.h

    FORMS +=
    sortdialog.ui
    @

    I do not know why the code line @layout()->setSizeConstraint(QLayout::SetFixedSize);@ crashes !
    Thanks



  • Can you design your GUI using internal designer in QT Creator? Your book (C++ GUI Programing with QT) been released in 2008. QT Creator been created later. What version of your QT? Maybe it solves your problem.



  • Yes,In the book at page 13 says "Qt designer" so that existed at that moment but not as an integrated internal tool.


  • Lifetime Qt Champion

    Hi,

    Just to be sure, did you set a layout on your designer UI ?



  • When I followed the book instruction I realised that the vertical layout was missed.
    Unfortunately I do not know how one can attach the sortdialog.ui file to this post since every post have to be limited in size.

    I think I fixed the problem but I do not know why my dialog layout is not similar to the one that is in found in the book.
    Thanks



  • This is writer's web page http://www.qtrac.eu/marksummerfield.html

    Here he says: Walter Dale has ported the book's examples to Qt 5

    "example files ":http://www.qtrac.eu/C++-GUI-Programming-with-Qt4-2nd-edition-qt5-examples.7z


Log in to reply
 

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