[英]How to change text dynamically in a qlabel to get next value of the database by a pushbutton?
I want to change the text in my label by the next value in the database from a pushbutton.我想通过按钮通过数据库中的下一个值更改我的 label 中的文本。 I tried the following code, it didn't work-
我尝试了以下代码,它没有用-
void category::on_pushButton_clicked()
{
QString d;
QSqlQuery qry;
QVariant b=0,s=0;
b = qry.exec("select count id from category");
if(b>=s)
{
s++;
qry.prepare("select heading from category");
qry.exec();
d=qry.value(0).toString();
ui->label_2->setText(d);
}}
It shows the error:-"invalid operands to binary expression('QVariant' and 'QVariant')" in the if statement- error picture(for more understanding)它在 if 语句错误图片中显示错误:-“二进制表达式的无效操作数('QVariant' 和'QVariant')”(为了更多理解)
I changed QVariant to int, and it didn't show any error but when i run it doesn't change the text on clicking pushbutton我将 QVariant 更改为 int,它没有显示任何错误,但是当我运行它时,它不会更改单击按钮时的文本
Firstly, you should check it in this way: "if (qry.exec())".首先,您应该以这种方式检查它:“if (qry.exec())”。 Secondly, you can see what's wrong with this "QString log = qry.lastError().text();"
其次,你可以看到这个“QString log = qry.lastError().text();”有什么问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.