一. 技巧与资料
- 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视频教程:
- 4 Qt Designer 文档: https://doc.qt.io/archives/qt-4.8/designer-using-containers.html
二. 开发问题
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 是去焦点不能更新
ui->editTotal->repaint();
this->repaint();
this->parentWidget()->repaint();
this->parentWidget()->parentWidget()->repaint();
6. calling ‘**’ with incomplete return type
解决方法是,在项目头文件中,添加相应的头文件包含,在本题中是
#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
输入下面的命令,然后重启:
baidu@localhost ~ % defaults write com.apple.dt.lldb DefaultPythonVersion 2
9. 解决中文乱码问题
在 main.cpp 的 main
函数中添加如下两行
#include "mainwindow.h"
#include <QApplication>
#include <QTextCodec>
int main(int argc, char *argv[])
{
// 解决汉字乱码问题
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}