我正在尝试编译“ Hello World!” Qt的应用程序但在编译时出现以下错误:‘class QApplication’ has no member named ‘setMainWidget’
,但我不确定为什么,我的源文件如下:
/****************************************************************
**
** Qt tutorial 1
**
****************************************************************/
#include <qapplication.h>
#include <qpushbutton.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );
a.setMainWidget( &hello );
hello.show();
return a.exec();
}
然后我使用以下CMakeLists.txt用cmake
创建了Makefile:
cmake_minimum_required(VERSION 3.1.0)
project(hello_world)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed
set(CMAKE_AUTOMOC ON)
# Create code from a list of Qt designer ui files
#set(CMAKE_AUTOUIC ON)
# Find the QtWidgets library
find_package(Qt5 COMPONENTS Widgets REQUIRED)
# Populate a CMake variable with the sources
set(hello_world_SRCS
main.cpp
)
# Tell CMake to create the helloworld executable
add_executable(hello_world WIN32 ${hello_world_SRCS})
# Use the Widgets module from Qt 5
target_link_libraries(hello_world Qt5::Widgets)
我在做什么错了?