使用Qt Creator和OpenCV制作一个简单的程序

时间:2015-02-16 02:45:38

标签: c++ qt opencv makefile qt-creator

这是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。你知道可能出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

您忘记包含MainWindow类中的代码。也许这就是你问题的原因。 你能单独编译你的main.cpp吗?