使用Qt Creator和OpenCV制作一个简单的程序
Using Qt Creator and OpenCV to make a simple program
这里是Qt工程中的.pro文件:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = abc123
TEMPLATE = app
LIBS += -L/usr/local/lib
INCLUDEPATH += /usr/local/include
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
当我尝试编译这段代码时,Qt 给了我 19 个不同的错误(无论我自己在 类 中写了什么):
/Users/user0/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:44: error: variable has incomplete type 'class Q_WIDGETS_EXPORT'
class Q_WIDGETS_EXPORT QSizePolicy
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:44: error: expected ';' after top level declarator
class Q_WIDGETS_EXPORT QSizePolicy
^
;
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
Q_DECLARE_OPERATORS_FOR_FLAGS(QSizePolicy::ControlTypes)
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:162: error: variable has incomplete type 'Q_WIDGETS_EXPORT'
Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:162: error: expected ';' after top level declarator
Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
^
;
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:163: error: redefinition of 'QDataStream'
Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:163: error: expected ';' after top level declarator
Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
^
;
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:167: error: variable has incomplete type 'Q_WIDGETS_EXPORT'
Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &);
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:167: error: expected ';' after top level declarator
Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &);
^
;
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:170: error: expected a class or namespace
inline void QSizePolicy::transpose() {
^
/usr/local/include/QtGui/qcursor.h:171: error: must use 'class' tag to refer to type 'QDataStream' in this scope
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &outS, const QCursor &cursor);
^
class
/usr/local/include/QtGui/qcursor.h:171: error: must use 'class' tag to refer to type 'QDataStream' in this scope
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &outS, const QCursor &cursor);
^
class
我使用的是 Qt 5.4.0 版本,我的操作系统是 OS X 10.9.4。你知道哪里出了问题吗?
您忘记包含主窗口中的代码 class。也许这就是你的问题的原因。
你能单独编译你的 main.cpp 吗?
这里是Qt工程中的.pro文件:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = abc123
TEMPLATE = app
LIBS += -L/usr/local/lib
INCLUDEPATH += /usr/local/include
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
当我尝试编译这段代码时,Qt 给了我 19 个不同的错误(无论我自己在 类 中写了什么):
/Users/user0/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:44: error: variable has incomplete type 'class Q_WIDGETS_EXPORT'
class Q_WIDGETS_EXPORT QSizePolicy
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:44: error: expected ';' after top level declarator
class Q_WIDGETS_EXPORT QSizePolicy
^
;
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
Q_DECLARE_OPERATORS_FOR_FLAGS(QSizePolicy::ControlTypes)
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:158: error: expected a class or namespace
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:162: error: variable has incomplete type 'Q_WIDGETS_EXPORT'
Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:162: error: expected ';' after top level declarator
Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &);
^
;
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:163: error: redefinition of 'QDataStream'
Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:163: error: expected ';' after top level declarator
Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &);
^
;
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:167: error: variable has incomplete type 'Q_WIDGETS_EXPORT'
Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &);
^
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:167: error: expected ';' after top level declarator
Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &);
^
;
/Users/user05/Qt5.4.0/5.4/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:170: error: expected a class or namespace
inline void QSizePolicy::transpose() {
^
/usr/local/include/QtGui/qcursor.h:171: error: must use 'class' tag to refer to type 'QDataStream' in this scope
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &outS, const QCursor &cursor);
^
class
/usr/local/include/QtGui/qcursor.h:171: error: must use 'class' tag to refer to type 'QDataStream' in this scope
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &outS, const QCursor &cursor);
^
class
我使用的是 Qt 5.4.0 版本,我的操作系统是 OS X 10.9.4。你知道哪里出了问题吗?
您忘记包含主窗口中的代码 class。也许这就是你的问题的原因。 你能单独编译你的 main.cpp 吗?