cmake 和 Qt 沸腾板,无法初始化类型为"QMainWindow *"错误的参数
cmake and Qt boilderplate, cannot initialize a parameter of type 'QMainWindow *' error
im试图使用cmake构建一个样板c++应用程序,该应用程序在名为main_window.xml的.ui文件中定义了一个主窗口。我遵循了一些教程,并试图拼凑出一种方法,但我的知识充其量是不完整的,我遇到了一个不知道如何修复的错误。
有人知道我哪里出了问题,或者我是否选对了树。
这是主.cpp
#include <QApplication>
#include "ui_main_window.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *widget = new QWidget;
Ui::MainWindow ui;
ui.setupUi(widget);
widget->show();
return app.exec();
}
这是CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
PROJECT(test_proj)
FIND_PACKAGE(Qt4 REQUIRED)
# include the current binary output directory as thats where the intermediate Qt fiels will be placed
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
# set sources of program
# only files that need preprocessgin by Qt need be included
SET(test_proj_SOURCES main.cpp)
SET(test_proj_HEADERS ui_main_window.h)
SET(test_proj_FORMS main_window.ui)
# this block creates .cpp and .h files from the .ui files
QT4_WRAP_CPP(test_proj_HEADERS_MOC ${test_proj_HEADERS})
QT4_WRAP_UI(test_proj_FORMS_HEADERS ${test_proj_FORMS})
# QT4_ADD_RESOURCES(test_proj_RESOURCES_RCC ${test_proj_RESOURCES})
ADD_EXECUTABLE(test_proj ${test_proj_SOURCES}
${test_proj_HEADERS}
${test_proj_FORMS})
TARGET_LINK_LIBRARIES(test_proj ${QT_LIBRARIES})
这是我得到的编译错误
Jonathans-MacBook-Pro:build jonathantopf$ make clean;make
[ 50%] Generating ui_main_window.h
Scanning dependencies of target laser_scan
[100%] Building CXX object CMakeFiles/laser_scan.dir/main.cpp.o
/projects/laser_scanner/src/main.cpp:49:17: error: cannot initialize a parameter of type 'QMainWindow *' with an lvalue of type
'QWidget *'
ui.setupUi(widget);
^~~~~~
/projects/laser_scanner/build/ui_main_window.h:48:31: note: passing argument to parameter 'MainWindow' here
void setupUi(QMainWindow *MainWindow)
^
1 error generated.
make[2]: *** [CMakeFiles/laser_scan.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/laser_scan.dir/all] Error 2
make: *** [all] Error 2
Jonathans-MacBook-Pro:build jonathantopf$
您的主窗口是从QMainWindow
继承的,因此您应该在主函数中将QWidget
替换为QMainWindow
。
然而,有一个没有表单类的表单是不寻常的。我建议您在QtCreator中使用"添加新的-Qt-Designer表单类"来创建一个类。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- 对 QMainWindow 使用 std::unique_ptr 时退出时出现 QT 应用程序分段错误
- 使用CMake构建Qt项目并从QMainWindow继承会导致未引用的vtable错误
- Qt中的错误:QMainWindowLayout::addItem:请改用公共QMainWindow API
- cmake 和 Qt 沸腾板,无法初始化类型为"QMainWindow *"错误的参数