Qt使用问题记录整理

1.中文显示问题
使用QStringLiteral
例:test_label = new QLabel(QStringLiteral(“型号:”));

2.标题窗口最大最小化问题
setWindowFlags(Qt::WindowCloseButtonHint|Qt::WindowMinimizeButtonHint);
WindowCloseButtonHint与WindowMinimizeButtonHint对应不同选项

3.初始化时读取数据量太大时,return app.exec()未执行之前 窗口卡住
界面构建完界面之后调用 QCoreApplication::processEvents();//刷新显示

4.QTextEdit右键菜单为英文问题
国际化,加载翻译资源文件:
QTranslator translator;
translator.load(“:/qt_zh_CN”);
app.installTranslator(&translator);
5.隐藏QMessageBox中的按钮

QDialogButtonBox *child_button = test_qmessagebox.findChild();
child_button->hide();
qmessagebox.show();

6.char* 转化为Qstring*

char *test_char = "abcd";
QString test_string=test_string.fromLocal8Bit(test_char);

7.Qstring* 转化为char*

QString test_qstring = "abcd";
QByteArray ba = test_qstring.toLatin1();
char *test_char=ba.data();

8.double 转换为Qstring

double test_double = 1.01;
QString test_qstring =QString::number(test_double,0,6);

猜你喜欢

转载自blog.csdn.net/weixin_43002236/article/details/81806923