Segmentation fault in setupUi() method



  • Hello everyone,

    I'm experiencing a strange error with a dialog box. I designed the dialog box with QtDesigner and used multi-inheritance to code it's functionality. When I launch the dialog box, I receive a segmentation fault. The debugger indicates that it's this line which causes the error
    @ label->setObjectName(QString::fromUtf8("label"));
    @
    which is in the setupUi() method of my dialog box.

    And I have this message in the application output
    @*** glibc detected *** /home/shiru/projects/app-build-desktop-release/bin/app: corrupted double-linked list: 0x0850e208 ***
    @
    followed by a backtrace
    @======= Backtrace: =========
    /lib/i386-linux-gnu/libc.so.6(+0x6b961)[0x1036961]
    /lib/i386-linux-gnu/libc.so.6(+0x6e99c)[0x103999c]
    /lib/i386-linux-gnu/libc.so.6(__libc_malloc+0x63)[0x103af53]
    /usr/lib/libQtCore.so.4(_Z7qMallocj+0x1d)[0xc4db8d]
    /usr/lib/libQtCore.so.4(_ZN7QStringC1EiN2Qt14InitializationE+0x2c)[0xc9a07c]
    /usr/lib/libQtCore.so.4(+0x18bd7a)[0xd7ed7a]
    /usr/lib/libQtCore.so.4(_ZN7QString8fromUtf8EPKci+0x43)[0xc9bf33]
    /home/shiru/projects/app-build-desktop-release/plugins/libdsale.so(_ZN17Ui_MakeSaleDialog7setupUiEP7QDialog+0x1d8)[0x2d7b39e]
    /home/shiru/projects/app-build-desktop-release/plugins/libdsale.so(_ZN14MakeSaleDialogC2EP7QWidget+0xb2)[0x2d796ca]
    /home/shiru/projects/app-build-desktop-release/plugins/libdsale.so(_ZN14SaleMainWidget8makeSaleEv+0x33)[0x2d70ebf]
    /home/shiru/projects/app-build-desktop-release/plugins/libdsale.so(_ZN14SaleMainWidget11qt_metacallEN11QMetaObject4CallEiPPv+0x8a)[0x2d8c114]
    /usr/lib/libQtCore.so.4(_ZN11QMetaObject8metacallEP7QObjectNS_4CallEiPPv+0x3a)[0xd4e6ba]
    ....@

    But sometimes, I have this in the application output
    @*** glibc detected *** /home/shiru/projects/app-build-desktop-release/bin/app: realloc(): invalid old size: 0x08598a50 ***
    @

    And the debugger indicates another line in the setupUi() method

    @priceSpinBox->setMinimum(1);
    @

    I don't understand this problem, can someone help me ?

    I'm using Qt 4.7.2 on Ubuntu 11.04.

    Thank you.



  • Maybe these lines don't cause errors. Try to put some qDebug() around these lines and see your app's output.



  • Please provide a more complete example, especially code showing the call to setupUi(). Your memory most likely gets corrupted long before the code you've shown.



  • This is the complete code of my class

    @#include "makesaledialog.h"

    #include <QtCore/QDebug>
    #include <QtCore/QDate>
    #include <QtCore/QSettings>
    #include <QtGui/QCloseEvent>
    #include <QtGui/QCompleter>

    #include <sale/sale.h>
    #include <sale/sqlmodels/vendormodel.h>
    #include <sale/sqlmodels/customermodel.h>
    #include <sale/sqlmodels/salemodel.h>

    #include <repository/repository.h>
    #include <repository/repositoryproduct.h>
    #include <repository/sqlmodels/repositorymodel.h>

    #include <utils.h>

    using namespace Px;

    MakeSaleDialog::MakeSaleDialog(QWidget *parent) :
    QDialog(parent)
    {
    setupUi(this);

    saleOptionsGroupBox->setVisible(false);
    
    readSettings();
    
    initialise();
    
    setupOptionsComboBoxes();
    setupComboBoxes();
    setupCompleter();
    
    initialiseMemosAndList();
    

    }

    void MakeSaleDialog::initialise()
    {
    Sale::List list = Sale::fetchByQuery("WHERE sale_date = '" + QDate::currentDate().toString("dd/MM/yyyy") + "'");

    saleNumberEdit->setText(QVariant(list.size() + 1).toString());
    

    }

    void MakeSaleDialog::setupOptionsComboBoxes()
    {
    QSettings settings;

    RepositoryModel *repositoryModel = new RepositoryModel;
    repositoryModel->select();
    
    repositoryComboBox->setModel(repositoryModel);
    repositoryComboBox->setModelColumn(Repository::NameColumn);
    
    int defaultRepositoryID = settings.value("saleoptions/default_repository_id", 0).toInt();
    Repository::Pointer repository = Repository::fetchByPrimaryKey(defaultRepositoryID);
    
    if(repository->isValid())
        repositoryComboBox->setCurrentIndex(repositoryComboBox->findText(repository->name()));
    
    SaleTypeModel *saleTypeModel = new SaleTypeModel;
    saleTypeModel->select();
    
    saleTypeComboBox->setModel(saleTypeModel);
    saleTypeComboBox->setModelColumn(SaleType::NameColumn);
    
    int defaultSaleTypeID = settings.value("saleoptions/default_sale_type_id", 0).toInt();
    SaleType::Pointer saleType = SaleType::fetchByPrimaryKey(defaultSaleTypeID);
    
    if(saleType->isValid())
        saleTypeComboBox->setCurrentIndex(saleTypeComboBox->findText(saleType->name()));
    
    PaymentModeModel *paymentModeModel = new PaymentModeModel;
    paymentModeModel->select();
    
    paymentModeComboBox->setModel(paymentModeModel);
    paymentModeComboBox->setModelColumn(PaymentMode::NameColumn);
    
    int defaultPaymentModeID = settings.value("saleoptions/default_payment_mode_id", 0).toInt();
    PaymentMode::Pointer paymentMode = PaymentMode::fetchByPrimaryKey(defaultPaymentModeID);
    
    if(paymentMode->isValid())
        paymentModeComboBox->setCurrentIndex(paymentModeComboBox->findText(paymentMode->name()));
    

    }

    void MakeSaleDialog::setupComboBoxes()
    {
    VendorModel *vendorModel = new VendorModel;
    vendorModel->select();

    vendorComboBox->setModel(vendorModel);
    vendorComboBox->setModelColumn(Vendor::NameColumn);
    
    CustomerModel *customerModel = new CustomerModel;
    customerModel->select();
    
    customerComboBox->setModel(customerModel);
    customerComboBox->setModelColumn(Customer::NameColumn);
    

    }

    void MakeSaleDialog::setupCompleter()
    {
    m_designationModel = new QStringListModel;
    m_designationModel->setStringList(m_designationList);

    QCompleter *designationCompleter = new QCompleter(this);
    designationCompleter->setModel(m_designationModel);
    designationCompleter->setCaseSensitivity(Qt::CaseInsensitive);
    
    designationEdit->setCompleter(designationCompleter);
    

    }

    void MakeSaleDialog::initialiseMemosAndList()
    {
    QString repositoryName = repositoryComboBox->currentText();

    Repository::Pointer repository = Repository::fetchFirstByQuery("WHERE repository_name = '" + repositoryName + "'");
    
    if(repository->isValid())
    {
        RepositoryProduct::List list = RepositoryProduct::fetchByQuery("WHERE repository_id = " + QVariant(repository->id()).toString());
    
        foreach(RepositoryProduct::Pointer repoProduct, list)
        {
            ProviderProduct::Pointer providerProduct = repoProduct->providerProduct();
            Product::Pointer product = providerProduct->coreProduct();
    
            QString designation = getProductDesignation(product);
            designation += providerProduct->provider()->name() + " / " + repoProduct->entryDateInStock().toString("dd/MM/yyyy")
                    + " / " + repoProduct->expireDate().toString("dd/MM/yyyy");
    
            quantityMemo[designation] = repoProduct->quantity();
            priceMemo[designation] = providerProduct->price();
    
            qDebug() << designation;
    
            m_designationList << designation;
        }
    }
    

    }

    QString MakeSaleDialog::getProductDesignation(Product::Pointer p)
    {
    QString name = p->name();
    QString dosage = p->dosage()->name();
    QString form = p->form()->name();
    QString packaging = p->packaging()->name();

    QString designation = name;
    
    if(dosage != Product::UnAvailable)
        designation += " " + dosage;
    
    if(form != Product::UnAvailable)
        designation += " " + form;
    
    if(packaging != Product::UnAvailable)
        designation += " " + packaging;
    
    return designation;
    

    }

    void MakeSaleDialog::changeEvent(QEvent *e)
    {
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
    retranslateUi(this);
    break;
    default:
    break;
    }
    }

    void MakeSaleDialog::closeEvent(QCloseEvent *e)
    {
    writeSettings();
    e->accept();
    }

    void MakeSaleDialog::readSettings()
    {
    QSettings settings;
    resize(settings.value("makesaledialog/size", QSize(954, 693)).toSize());
    }

    void MakeSaleDialog::writeSettings()
    {
    QSettings settings;
    settings.setValue("makesaledialog/size", size());
    }@



  • And the offending .ui file?


Log in to reply
 

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