gpt4 book ai didi

c++ - qt bindvalue() 无法动态绑定(bind)值

转载 作者:太空宇宙 更新时间:2023-11-04 11:31:36 24 4
gpt4 key购买 nike

下面是sql语句

QString  myQuery = "UPDATE myTable SET myAttr = :myAttr WHERE ID = 1";    

//m_query is a QSqlQuery object pointer
m_query->prepare(myQuery);
QString value = "some value";
m_query->bindValue(":myAttr", QVariant(value)) ;
m_query->exec();

But when I print the executedQuery, it shows the value for **myAttr = ?**

执行不会引起任何关于 bindValue() 的提示。有人知道这里发生了什么吗?我正在使用 QT5.2.1 MinGW_32bits提前致谢。

最佳答案

我已经使用以下方法解决了这个问题:

change the  :myAttr to :MYATTR

当您绑定(bind)值时,请遵循相同的格式。

m_query->bindValue(":MYATTR", QVariant(value)) **strong text**

我认为这是新版 QTCreator 的问题。

关于c++ - qt bindvalue() 无法动态绑定(bind)值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24563602/

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