c++ - 如何阻止 for 循环直到执行 sqlite 查询?

标签 c++ qt sqlite qt4

我正在用 Qt 编写程序,下面是我的代码的一部分:

for(int row=0; row < 15; row++)
    {
        for(int column=0; column < 12; column++ )
        {
            if(query->exec(db->getInsertQuery(row,column)))
            {

            }else
                qDebug() << "Failed to insert cell";
        }
    }

当我运行这个程序时,它进入“无响应”状态。当我运行时

    query->exec(db->getInsertQuery(0,0));
    query->exec(db->getInsertQuery(0,1));
    ....

代替 for 循环程序运行正常,但我不能在我的程序中写这么多行。您能否建议我阻止 for 循环直到执行查询的方法以及如何在某些框中显示进度条直到 for 循环完成?

最佳答案

如果您正在使用 QtSql,我假设您应该使用 execBatch() 方法来完成此类任务

Example

QSqlQuery q;
q.prepare("insert into myTable values (?, ?)");

QVariantList ints;
ints << 1 << 2 << 3 << 4;
q.addBindValue(ints);

QVariantList names;
names << "Harald" << "Boris" << "Trond" << QVariant(QVariant::String);
q.addBindValue(names);

if (!q.execBatch())
    qDebug() << q.lastError();

关于c++ - 如何阻止 for 循环直到执行 sqlite 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21216863/

相关文章:

c++ - 链接器找不到 C++ 静态成员

c++ - 在 Qt 中检测进程已完成

Android SQLite DB插入包含破折号/"-"的值的字段

python - 使用python在sqlite3中附加数据库

c++:为什么执行回调但不执行回调定义之前的函数?

C++ 调整/优化

c++ - QTableView如何获取滚动条所在行的位置

c++ - QProcess.execute() 一个 DOS 命令

sql - 如何在 SQLite3 和 Rails 3.1 中打开 REGEXP?

c# - C++/CLI 包装器只能在 x86 机器上正常工作,我需要 x64 机器