-1
我正在使用QT,我想用一個sqlite數據庫來繪製一個帶有x和y座標以及寬度和高度尺寸的橢圓。Qt&sqlite:無法將query.value保存在一個變量中
我已經成功實現了數據庫(.db文件位於我的工作文件夾中,在這種情況下是發佈文件夾),現在我想保存在變量中插入到數據庫中的值。
QSqlQuery query;
QString queryString = QString::fromUtf8("select * from tableEllipse;");
if(!query.exec(queryString))
{
qDebug() << "Error"
}
while (query.next())
{
int id = query.value(0).toInt;
int x = query.value(1).toInt;
int y = query.value(2).toInt;
int width = query.value(3).toInt;
int height = query.value(4).toInt;
qDebug() << x << y << width << height;
}
我用一些值填充了我的表一次。如果我嘗試運行我的程序,我得到這個以下錯誤:
不能轉換從類型「的QVariant :: toInt 'INT(::的QVariant)(BOOL *)const的' 輸入 '詮釋'
但在我的數據庫中,所有的值都是整數!
CREATE TABLE tableEllipse
(
ellipseID integer primary key,
ellipseX integer,
ellipseY integer,
ellipseWidth integer,
ellipseHeight integer
);
你需要使用括號來調用一個方法在C++中。另外,如果你沒有傳遞UTF8字符,那麼使用QString的'fromUtf8()'方法沒有意義。 – MrEricSir