1、QObject::tr() 的使用
ui->textEdit->append(QObject::tr("%1 %2 数据库连接失败%3")
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
.arg(stationName)
.arg(sqldb.lastError().text()));
2、导出textEdit文本内容到log.txt中
void myApp::textEditExport(){
ui->textEdit->append(QObject::tr("%1 Export Success").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")));
QFile log("log.txt");
QTextStream logStream(&log);
QString str = ui->textEdit->toPlainText();
if(!log.open(QIODevice::WriteOnly)){
ui->textEdit->append(QObject::tr("日志文件log.txt打开失败 %1").arg(log.errorString()));
}
// log.write();
logStream << str;
log.close();
}
3、volatile 关键字使变量在任何时候都保持是最新的值
volatile int index = 0; // volatile 关键字使变量在任何时候都保持是最新的值
4、当一个事件处理程序知道自己将执行耗时很长的操作时,可以调用QCoreApplication::processEvents() 方法,等待消息队列中的方法都执行完再执行。