我的CMakeLists.txt看起来像:
cmake_minimum_required(VERSION 2.8)
if(CMAKE_BUILD_TYPE STREQUAL Release)
SET(CMAKE_BUILD_TYPE Release)
SET (PROJECT_NAME location_recognition)
message("Release mode")
else()
SET(CMAKE_BUILD_TYPE Debug)
SET (PROJECT_NAME location_recognition)
SET(CMAKE_CXX_FILES "-g -Wall")
message("Debug mode")
endif()
#find QT libraries
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(Boost REQUIRED)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )
# We need add -DQT_WIDGETS_LIB when using …Run Code Online (Sandbox Code Playgroud) 我有一个使用CMake 2.8.9的相对简单的Qt 5.0项目:
的CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.9)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
project(hello-world)
find_package(Qt5Widgets REQUIRED)
qt5_wrap_ui(hello-world_UI MainWindow.ui)
add_executable(hello-world MainWindow.cpp main.cpp ${hello-world_UI})
qt5_use_modules(hello-world Widgets)
Run Code Online (Sandbox Code Playgroud)
MainWindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
virtual ~MainWindow();
private:
Ui::MainWindow * const ui;
};
#endif // CMAINWINDOW_H
Run Code Online (Sandbox Code Playgroud)
MainWindow.cpp:
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow()
: ui(new Ui::MainWindow)
{
}
MainWindow::~MainWindow()
{
delete ui;
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中:
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char * argv[])
{ …Run Code Online (Sandbox Code Playgroud) 我创建了表单,将其保存在项目目录中。现在我想添加一些代码。所以,我创建了头文件:
#ifndef SORTDIALOG_H
#define SORTDIALOG_H
#include <QtWidgets/QDialog>
#include <QtWidgets/QWidget>
#include "ui_sortdialog.h"
class SortDialog: public QDialog, public Ui::SortDialog
{
Q_OBJECT
public:
SortDialog(QWidget *parent=0);
void setColumnRange(QChar first, QChar last);
}
#endif // SORTDIALOG_H
Run Code Online (Sandbox Code Playgroud)
在编写代码 Qt creator 看到 ui_sortdialog.h,例如,我可以看到“Ui”命名空间。但是当我试图编译器写到 ui_sortdialog.h 没有找到
C:\Qt\Qt5.1.1\Tools\QtCreator\bin\untitled2\sortdialog.h:8: error: ui_sortdialog.h: No such file or directory
#include "ui_sortdialog.h"
^
Run Code Online (Sandbox Code Playgroud) 我正在使用Qt创建一个GUI应用程序; 我尝试hello world使用Qt并且它工作得很好,但是当我创建自定义列表小部件undefined reference to vtable时,我在编译时遇到错误:
我正在使用eclipse和c ++
#ifndef QMENUFILTER_H_
#define QMENUFILTER_H_
#include <qmenu.h>
class CustomMenuFilter : QMenu
{
Q_OBJECT
public:
CustomMenuFilter () ;
~CustomMenuFilter() ;
private:
QMenu FilterMenu;
QAction *AddFilterAct ;
QAction *DeleteFilterAct ;
Q_SLOT
void contextMenuEvent(QContextMenuEvent *event);
};
#endif /* QMENUFILTER_H_ */
#include "QMenuFilter.h"
CustomMenuFilter::CustomMenuFilter():QMenu()
{
DeleteFilterAct = new QAction("DeleteFilter" , this);
AddFilterAct = new QAction("AddFilter" , this);
AddFilterAct->setText("AddFilter");
DeleteFilterAct->setText("DeleteFilter");
}
Run Code Online (Sandbox Code Playgroud)
日志文件:http://pastebin.com/raw.php? i = qZes6bkm