0

I followed Netbeans' guide to create a basic application with QT. The project builds successfully but fail to Run with no explanation.

I'm running W8 x64 with MinGW and QT4.8 (downloaded from netbeans' guide links).

Here is the C++ files code (for the most part created automatically) :

main.cpp :

#include <QtGui/QApplication>
#include "UI_main.h"

int main(int argc, char *argv[]) {
    // initialize resources, if needed
    // Q_INIT_RESOURCE(resfile);

    QApplication app(argc, argv);

    // create and show your widgets here
    UI_main main_w;
    main_w.show();

    return app.exec();
}

UI_main.h :

#ifndef _UI_MAIN_H
#define _UI_MAIN_H

#include "ui_UI_main.h"

class UI_main : public QMainWindow {
    Q_OBJECT
public:
    UI_main();
    virtual ~UI_main();
private:
    Ui::UI_main widget;
};

#endif  /* _UI_MAIN_H */

ui_UI_main.h :

#ifndef UI_UI_MAIN_H
#define UI_UI_MAIN_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QGroupBox>
#include <QtGui/QHeaderView>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QStatusBar>
#include <QtGui/QWidget>

QT_BEGIN_NAMESPACE

class Ui_UI_main
{
public:
    QWidget *centralwidget;
    QGroupBox *groupBox;
    QMenuBar *menubar;
    QStatusBar *statusbar;

    void setupUi(QMainWindow *UI_main)
    {
        if (UI_main->objectName().isEmpty())
            UI_main->setObjectName(QString::fromUtf8("UI_main"));
        UI_main->resize(800, 600);
        centralwidget = new QWidget(UI_main);
        centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
        groupBox = new QGroupBox(centralwidget);
        groupBox->setObjectName(QString::fromUtf8("groupBox"));
        groupBox->setGeometry(QRect(300, 210, 120, 80));
        UI_main->setCentralWidget(centralwidget);
        menubar = new QMenuBar(UI_main);
        menubar->setObjectName(QString::fromUtf8("menubar"));
        menubar->setGeometry(QRect(0, 0, 800, 21));
        UI_main->setMenuBar(menubar);
        statusbar = new QStatusBar(UI_main);
        statusbar->setObjectName(QString::fromUtf8("statusbar"));
        UI_main->setStatusBar(statusbar);

        retranslateUi(UI_main);

        QMetaObject::connectSlotsByName(UI_main);
    } // setupUi

    void retranslateUi(QMainWindow *UI_main)
    {
        UI_main->setWindowTitle(QApplication::translate("UI_main", "UI_main", 0, QApplication::UnicodeUTF8));
        groupBox->setTitle(QApplication::translate("UI_main", "GroupBox", 0, QApplication::UnicodeUTF8));
    } // retranslateUi

};

namespace Ui {
    class UI_main: public Ui_UI_main {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_UI_MAIN_H

UI_main.cpp :

#include "UI_main.h"

UI_main::UI_main() {
    widget.setupUi(this);
}

UI_main::~UI_main() {
}

UI_main.ui only contains a group box created with QTDesigner.

The error msg :

RUN FAILED (exit value -1 073 741 819, total time: 2s)

I tried running it with Windows console and with compatibility mode W7 and XP with the same result.

Any Ideas ? Thank by advance.

4

2 回答 2

1

The code is okay and runs without any error in Qt Creator.

enter image description here

exit value -1 073 741 819 means you are using wrong library link or mismatched header or build versions. Please check project linkers, their versions, arch etc.

于 2013-03-31T18:53:11.567 回答
0

I finally found the source of the problem by uninstalling everything (Qt and MinGW) and restarting the guide from the beginning (paying attention to versions etc. ) . The only thing that was different (apparently) is that I had installed MSYS1.0 separately from MinGW installer. Now everything works well and I can carry on with my project. Thanks Muhammad Minhazul Haque for your help !

于 2013-04-10T09:02:37.033 回答