Qt 自动无法加载数据库为空
解决方式:main()
中设置QDir::setCurrent(QCoreApplication::applicationDirPath())
;即可
1、开机自启
void setAutoStart(bool enable) {QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);QString appName = QCoreApplication::applicationName();QString appPath = QCoreApplication::applicationFilePath().replace("/", "\\"); // 路径格式转换if (enable) {qDebug()<<"set auto run "<<enable;settings.setValue(appName, appPath); // 添加注册表项} else {qDebug()<<"set auto run "<<enable;settings.remove(appName); // 删除注册表项}
}
2、设置加载目录
int main(int argc, char *argv[])
{QApplication a(argc, argv);QDir::setCurrent(QCoreApplication::applicationDirPath());//关键点qInstallMessageHandler(QtlogOutput);...
}