Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ QT5/QSql bindValue查询不';行不通_C++_Mysql_Qt5_Qsqlquery_Bindvalue - Fatal编程技术网

C++ QT5/QSql bindValue查询不';行不通

C++ QT5/QSql bindValue查询不';行不通,c++,mysql,qt5,qsqlquery,bindvalue,C++,Mysql,Qt5,Qsqlquery,Bindvalue,我用QSql进行了一个查询 query.prepare("SELECT id,title,content FROM posts ORDER BY :field :order LIMIT :limit OFFSET :offset"); query.bindValue(":field",QVariant(field)); query.bindValue(":order",order); query.bindValue(":limit",limit); query.bindValue(":offse

我用QSql进行了一个查询

query.prepare("SELECT id,title,content FROM posts ORDER BY :field :order LIMIT :limit OFFSET :offset");
query.bindValue(":field",QVariant(field));
query.bindValue(":order",order);
query.bindValue(":limit",limit);
query.bindValue(":offset",offset);
我使用订单值作为“DESC”,但它不能正常工作。但是,当我这样做的时候

query.prepare("SELECT id,title,content FROM posts ORDER BY "+field+"  "+order+" LIMIT :limit OFFSET :offset");
query.bindValue(":limit",limit);
query.bindValue(":offset",offset);
它很好用,我不知道为什么。这些值的类型相同(QString和int)。有什么建议吗


谢谢。

为什么要将
字段
包装在
QVariant
中?我在“字段”和“顺序”中使用“QString”。“限制”和“偏移”是“int”,不能回答问题…抱歉。我弄错了。事实上,这个“QVariant(field)”不在那里,我在那里测试并复制了他。但是,与其他字段一样,我的代码中没有QVariant。