gpt4 book ai didi

c++ - Qt如何打开SQL Compact Server文件.sdf

转载 作者:行者123 更新时间:2023-11-28 06:06:31 27 4
gpt4 key购买 nike

我正在尝试使用 Qt 打开 SQL Compact Server 文件 .sdf。我有以下代码:

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("C:\\testresults.sdf");
bool Success = db.open();

sprintf(writeToMonitorBuffer, "dblastError = %s", (const char *)db.lastError().text().toLatin1());
writeToMonitor(writeToMonitorBuffer);

sprintf(writeToMonitorBuffer, "db.open(): Success/Fail = %s", Success ? "Pass" : "Fail");
writeToMonitor(writeToMonitorBuffer);

我收到错误消息:

dblastError = [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect

然后我得到:

db.open(): Success/Fail = Fail

我该如何解决这个问题?

最佳答案

\ 用于 escape sequences在 C++ 中,所以你需要这样做:

db.setDatabaseName("C:\\testresults.sdf");

关于c++ - Qt如何打开SQL Compact Server文件.sdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32278768/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com