1.新建Qt项目
Qt安装路径为/home/lzy/Downloads/qt
将Qt CMake prefix path设置为/home/lzy/Downloads/qt/5.12.12/gcc_64
或在CMakeLists中加入
set(CMAKE_PREFIX_PATH "/home/lzy/Downloads/qt/5.12.12/gcc_64")
2.使用qtdesigner
settings -> Tools ->External Tools
Program
填入designer
路径:/home/lzy/Downloads/qt/5.12.12/gcc_64/bin/designer
Agruments
填入:$FileName$
Working directory
填入:$ProjectFileDir$
对.ui
文件右键External Tools
3.ui文件报错
如果出现以下报错:
AutoUic error
-------------
"SRC:/mywidget.cpp"
includes the uic file "ui_MyWidget.h",
but the user interface file "MyWidget.ui"
could not be found in the following directories
"SRC:"
ninja: build stopped: subcommand failed.
settings -> Tools ->External Tools
Program
填入uic
路径:/home/lzy/Downloads/qt/5.12.12/gcc_64/bin/uic
Agruments
填入:$FileName$ -o ui_$FileNameWithoutExtension$.h
Working directory
填入:$FileDir$
右键Qt UIC打开.ui
文件生成代码
或者关掉clion重建一个项目也可以解决
4.QMainWindow模板缺失问题
Clion生成的UI文件没有central widget
其实Clion生成Qt的UI类是通过文件和代码模板实现的,Settings>>Editor>>File and Code Templates找到Qt Designer Form将里面的内容改为如下:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class</