如何设置OpenCV和Qt的链接以使用createButton?

时间:2012-07-28 10:48:57

标签: c++ opencv qt4

我正在查看opencv highgui示例(如connectedcomponents.cpp)并尝试习惯添加GUI元素。目前我正在尝试添加一个按钮:

void on_button(int, void*){
    cout << "click" << end;
}
//in main()
createButton("test",on_button);

但是我收到了链接错误:

g++ -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_CORE_LIB -I../../../QtSDK/Desktop/Qt/474/gcc/mkspecs/macx-g++ -I. -I../../../QtSDK/Desktop/Qt/474/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/474/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/474/gcc/include -I/opt/local/include -I../../../QtSDK/Desktop/Qt/474/gcc/include -I. -F/Users/george/QtSDK/Desktop/Qt/474/gcc/lib -o main.o main.cpp
g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o CVConnectedComponent main.o   -F/Users/george/QtSDK/Desktop/Qt/474/gcc/lib -L/Users/george/QtSDK/Desktop/Qt/474/gcc/lib /opt/local/lib/libopencv_core.dylib /opt/local/lib/libopencv_contrib.dylib /opt/local/lib/libopencv_highgui.dylib /opt/local/lib/libopencv_objdetect.dylib /opt/local/lib/libopencv_imgproc.dylib /opt/local/lib/libopencv_features2d.dylib /opt/local/lib/libopencv_video.dylib -framework QtCore -F/Users/george/Documents/Qt/CVConnectedComponent/../../../QtSDK/Desktop/Qt/474/gcc/lib/ 
Undefined symbols:
  "cv::createButton(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void (*)(int, void*), void*, int, bool)", referenced from:
      _main in main.o
make: Leaving directory `/Users/george/Documents/Qt/CVConnectedComponent'
ld: symbol(s) not found

据我所知,我没有正确地链接到QtCore库。 我是这样的:

mac: LIBS += -framework QtCore

和此:

mac: LIBS += -F$$PWD/../../../QtSDK/Desktop/Qt/474/gcc/lib/ -framework QtCore

INCLUDEPATH += $$PWD/../../../QtSDK/Desktop/Qt/474/gcc/include
DEPENDPATH += $$PWD/../../../QtSDK/Desktop/Qt/474/gcc/include

在Qt项目的.pro文件中,但没有运气。 我在osx 10.6.8上使用OpenCV 2.4.1和Qt 4.7.4。

在Qt Creator中链接到QtCore以在OpenCV中使用createButton的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

我重新安装了OpenCV,这次使用Qt支持并且代码工作正常。 仍然值得记住,默认情况下按钮将进入控制面板,正如reading some documentation所发现的那样:

OpenCV Qt GUI