使用Clion搭建qt5项目方法

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输入框不能输入中文的问题

下载https://github.com/JackieMium/libfcitxplatforminputcontextplugin.so/tree/master/lib-fcitx-plugin/debian.sid.20181208

改后缀为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
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黎汝聪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值