我是qt框架环境的新手,昨晚我应用了一些我在书中找到的示例,一切正常,但是今天当我启动QT创建者并尝试再次导入我的项目时,它崩溃了好几次。现在,当我创建一个项目并尝试运行它时,它会显示一个错误列表,尽管我没有对它进行任何更改。
试图改变qglobal.h但是再次犯了很多错误,尝试重新配置但没有运气,我还应该提一下创建者附带的例子可以运行并运行。
我在linux x86-32位计算机上使用qt-creator 5.4.0社区和gcc 4.6。
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
main.cpp中:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
.pro文件
#-------------------------------------------------
#
# Project created by QtCreator 2015-01-19T13:57:12
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
这是编译输出:
13:57:28: Starting: "/home/user/Qt/5.4/gcc/bin/qmake" /home/user/untitled1/untitled1.pro -r -spec linux-g++ CONFIG+=debug
13:57:28: The process "/home/user/Qt/5.4/gcc/bin/qmake" exited normally.
13:57:28: Starting: "/usr/bin/make"
/home/user/Qt/5.4/gcc/bin/uic ../untitled1/mainwindow.ui -o ui_mainwindow.h
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../Qt/5.4/gcc/mkspecs/linux-g++ -I../untitled1 -I../Qt/5.4/gcc/include -I../Qt/5.4/gcc/include/QtWidgets -I../Qt/5.4/gcc/include/QtGui -I../Qt/5.4/gcc/include/QtCore -I. -I. -I. -o main.o ../untitled1/main.cpp
In file included from ../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:38:0,
from ../Qt/5.4/gcc/include/QtWidgets/QMainWindow:1,
from ../untitled1/mainwindow.h:4,
from ../untitled1/main.cpp:1:
../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:49:44: error: invalid use of incomplete type 'class QWidget'
class Q_WIDGETS_EXPORT QTabWidget : public QWidget
^
In file included from ../Qt/5.4/gcc/include/QtGui/qpaintdevice.h:37:0,
from ../Qt/5.4/gcc/include/QtGui/qpixmap.h:37,
from ../Qt/5.4/gcc/include/QtGui/qicon.h:40,
from ../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:38,
from ../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:38,
from ../Qt/5.4/gcc/include/QtWidgets/QMainWindow:1,
from ../untitled1/mainwindow.h:4,
from ../untitled1/main.cpp:1:
../Qt/5.4/gcc/include/QtGui/qwindowdefs.h:47:7: error: forward declaration of 'class QWidget'
class QWidget;
^
In file included from ../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:38:0,
from ../Qt/5.4/gcc/include/QtWidgets/QMainWindow:1,
from ../untitled1/mainwindow.h:4,
from ../untitled1/main.cpp:1:
../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:157:20: error: 'QShowEvent' has not been declared
void showEvent(QShowEvent *);
^
../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:158:22: error: 'QResizeEvent' has not been declared
void resizeEvent(QResizeEvent *);
^
../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:159:24: error: 'QKeyEvent' has not been declared
void keyPressEvent(QKeyEvent *);
^
../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:160:21: error: 'QPaintEvent' has not been declared
void paintEvent(QPaintEvent *);
^
In file included from ../Qt/5.4/gcc/include/QtGui/qicon.h:37:0,
from ../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:38,
from ../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:38,
from ../Qt/5.4/gcc/include/QtWidgets/QMainWindow:1,
from ../untitled1/mainwindow.h:4,
from ../untitled1/main.cpp:1:
../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h: In member function 'QTabWidgetPrivate* QTabWidget::d_func()':
../Qt/5.4/gcc/include/QtCore/qglobal.h:964:95: error: 'd_ptr' was not declared in this scope
inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \
^
../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:168:5: note: in expansion of macro 'Q_DECLARE_PRIVATE'
Q_DECLARE_PRIVATE(QTabWidget)
^
../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h: In member function 'const QTabWidgetPrivate* QTabWidget::d_func() const':
../Qt/5.4/gcc/include/QtCore/qglobal.h:965:113: error: 'd_ptr' was not declared in this scope
inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \
^
../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:168:5: note: in expansion of macro 'Q_DECLARE_PRIVATE'
Q_DECLARE_PRIVATE(QTabWidget)
^
In file included from ../Qt/5.4/gcc/include/QtWidgets/QMainWindow:1:0,
from ../untitled1/mainwindow.h:4,
from ../untitled1/main.cpp:1:
../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h: At global scope:
../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:52:45: error: invalid use of incomplete type 'class QWidget'
class Q_WIDGETS_EXPORT QMainWindow : public QWidget
^
In file included from ../Qt/5.4/gcc/include/QtGui/qpaintdevice.h:37:0,
from ../Qt/5.4/gcc/include/QtGui/qpixmap.h:37,
from ../Qt/5.4/gcc/include/QtGui/qicon.h:40,
from ../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:38,
from ../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:38,
from ../Qt/5.4/gcc/include/QtWidgets/QMainWindow:1,
from ../untitled1/mainwindow.h:4,
from ../untitled1/main.cpp:1:
../Qt/5.4/gcc/include/QtGui/qwindowdefs.h:47:7: error: forward declaration of 'class QWidget'
class QWidget;
^
In file included from ../Qt/5.4/gcc/include/QtWidgets/QMainWindow:1:0,
from ../untitled1/mainwindow.h:4,
from ../untitled1/main.cpp:1:
../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:191:27: error: 'QContextMenuEvent' has not been declared
void contextMenuEvent(QContextMenuEvent *event);
^
In file included from ../Qt/5.4/gcc/include/QtGui/qicon.h:37:0,
from ../Qt/5.4/gcc/include/QtWidgets/qtabwidget.h:38,
from ../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:38,
from ../Qt/5.4/gcc/include/QtWidgets/QMainWindow:1,
from ../untitled1/mainwindow.h:4,
from ../untitled1/main.cpp:1:
../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h: In member function 'QMainWindowPrivate* QMainWindow::d_func()':
../Qt/5.4/gcc/include/QtCore/qglobal.h:964:95: error: 'd_ptr' was not declared in this scope
inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \
^
../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:196:5: note: in expansion of macro 'Q_DECLARE_PRIVATE'
Q_DECLARE_PRIVATE(QMainWindow)
^
../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h: In member function 'const QMainWindowPrivate* QMainWindow::d_func() const':
../Qt/5.4/gcc/include/QtCore/qglobal.h:965:113: error: 'd_ptr' was not declared in this scope
inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \
^
../Qt/5.4/gcc/include/QtWidgets/qmainwindow.h:196:5: note: in expansion of macro 'Q_DECLARE_PRIVATE'
Q_DECLARE_PRIVATE(QMainWindow)
^
../untitled1/main.cpp: In function 'int main(int, char**)':
../untitled1/main.cpp:8:7: error: 'class MainWindow' has no member named 'show'
w.show();
^
make: *** [main.o] Error 1
13:57:30: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled1 (kit: Desktop Qt 5.4.0 GCC 32bit)
When executing step "Make"
13:57:30: Elapsed time: 00:02.
答案 0 :(得分:0)
如果您因某些原因在Linux计算机上运行,有时在崩溃后某些配置文件会损坏。尝试重置配置,如果这没有帮助尝试重新安装。