Qt学习采坑记录

2020-09-05  本文已影响0人  天叔

一、QT 技巧/资料

  1. Qt creator for mac 细节配置
    https://www.jianshu.com/p/36777006f042

  2. Qt常用快捷键
    https://blog.csdn.net/fanyun_01/article/details/78939849
    cmd + i 自动缩进
    F1 可以查看文档

  3. Qt视频教程
    https://www.youtube.com/playlist?list=PLS1QulWo1RIZiBcTr5urECberTITj7gjA

  4. Qt Designer 文档
    https://doc.qt.io/archives/qt-4.8/designer-using-containers.html

二、QT开发问题记录

  1. mac上有些兼容问题,比如menubar显示规则和window不同
    https://doc.qt.io/qt-5/macos-issues.html
    Qt detects menu bars and turns them into Mac native menu bars

  2. 命令行编译,有时候报错不知道原因,可以通过命令行编译查看详细报错信息
    1)qmake 2)make

  3. .h文件定义了槽方法,必须在cpp文件实现,否则报错找不到文件,Qt的 slot机制吧

  4. ? 图标不显示

  5. LineEdit 是去焦点不能更新

    ui->editTotal->repaint();

    this->repaint();
    this->parentWidget()->repaint();
    this->parentWidget()->parentWidget()->repaint();
  1. calling '**' with incomplete return type
    解决方法是,在项目头文件中,添加相应的头文件包含,在本题中是
#include <QTextBlock>
  1. ToolButton关联Action只能在代码里操作。
    You can't link action to a button in QtDesigner, you do that in code. QtDesigner is used for easy GUI design.
    https://stackoverflow.com/questions/24038610/qt-4-designer-how-to-link-a-qtoolbutton-pushbutton-to-an-action
    ui->tBtnListIni->setDefaultAction(ui->actListIni);
  1. mac 上 qt creator debug 失败
    https://stackoverflow.com/questions/56687820/qt-creator-fails-to-start-debugging-on-mac/56711596#56711596
    输入下面命令,然后重启
baidu@localhost ~ % defaults write com.apple.dt.lldb DefaultPythonVersion 2
  1. 自定义qml中使用的控件,控件命名必须以大写字母开头,imageProcessor就不行,必须写成ImageProcessor才能通过编译

三、教程笔记

QT最核心的概念是“信号”与“槽”,客户端开发的套路大同小异,和iOS的界面开发类似。用Android中Button来理解:信号就是Button暴露出来一个事件接口,允许你setOnClickListener(),这个方法就是信号的传递,你new OnClickListener(func),func里的操作就是槽,Qt把这种观察者模式的实现简化封装了,你只需要定义click,触发后就会调用onClick,不用再setOnClickListener(new func...),把onClick和 func 通过connect链接起来就会自动触发


参考书籍:《Qt 5.9 c++开发指南》

四、c++部分

函数前后加const有什么区别:
https://blog.csdn.net/u010029439/article/details/80687360
前面加表示返回值不可更改,后面加表示不能修改class 属性

上一篇 下一篇

猜你喜欢

热点阅读