一. 技巧与资料

二. 开发问题

1. mac上有些兼容问题,比如menubar显示规则和windows不同

https://doc.qt.io/qt-5/macos-issues.html
Qt detects menu bars and turns them into Mac native menu bars

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

  • qmake
  • make

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

4. ? 图标不显示

5. LineEdit 是去焦点不能更新

  1. ui->editTotal->repaint();
  2. this->repaint();
  3. this->parentWidget()->repaint();
  4. this->parentWidget()->parentWidget()->repaint();

6. calling ‘**’ with incomplete return type

解决方法是,在项目头文件中,添加相应的头文件包含,在本题中是

  1. #include <QTextBlock>

7. 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

8. mac 上 Qt Creator Debug 失败

https://stackoverflow.com/questions/56687820/qt-creator-fails-to-start-debugging-on-mac/56711596#56711596
输入下面的命令,然后重启:

  1. baidu@localhost ~ % defaults write com.apple.dt.lldb DefaultPythonVersion 2

9. 解决中文乱码问题

在 main.cpp 的 main 函数中添加如下两行

  1. #include "mainwindow.h"
  2. #include <QApplication>
  3. #include <QTextCodec>
  4. int main(int argc, char *argv[])
  5. {
  6. // 解决汉字乱码问题
  7. QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  8. QTextCodec::setCodecForLocale(codec);
  9. QApplication a(argc, argv);
  10. MainWindow w;
  11. w.show();
  12. return a.exec();
  13. }