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>${NAMESPACE_SPECIFIER}${NAME}</class>
<widget class="${PARENT_CLASS}" name="${NAMESPACE_SPECIFIER}${NAME}">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>${NAME}</string>
</property>
#if( ${PARENT_CLASS} == "QMainWindow" )
<widget class="QWidget" name="centralWidget"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
#end
</widget>
#if( ${PARENT_CLASS} == "QMainWindow" )
<layoutdefault spacing="6" margin="11"/>
#end
<pixmapfunction/>
<connections/>
</ui>
5.Qt输入框不能输入中文的问题
改后缀为libfcitxplatforminputcontextplugin.so
,复制到/home/lzy/Downloads/qt/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts
和/home/lzy/Downloads/qt/5.12.12/gcc_64/plugins/platforminputcontexts
#并执行
chmod +x libfcitxplatforminputcontextplugin.so