PDA

View Full Version : Compilation problem with QSqlQuery::bindValue()



brevleq
1st November 2007, 11:34
I'm having a strange problem with the QSqlQuery::bindValue() sintax, my QT code is show above:

#include "ManipulaTipos.h"

#include <iostream>

using namespace std;

ManipulaTipos::ManipulaTipos(void){
}

void ManipulaTipos::adiciona(QString tabela,QString codigo,QString nome){
expressao="INSERT INTO ";
expressao.append(tabela);
expressao.append(" (codigo,nome) VALUES (:codigo, :nome)");
query.prepare(expressao);
query.bindValue(":codigo", codigo);
query.bindValue(":nome", nome);
query.exec();
}

QList<QStringList> ManipulaTipos::listar(QString tabela){
QString codigo;
QString nome;
QStringList registro;
expressao="SELECT * FROM ";
expressao.append(tabela);
query.prepare(expressao);
query.exec();
while(query.next()){
codigo=query.value(0).toString();
nome=query.value(1).toString();
registro<<codigo;
registro<<nome;
lista << registro;
}
return(lista);
}

void ManipulaTipos::remove(QString tabela,QString indice){
expressao="DELETE FROM ";
expressao.append(tabela);
expressao.append(" WHERE codigo==:indice");
query.prepare(expressao);
query.bindValue(":indice",indice);
query.exec();
}

void ManipulaTipos::atualiza(QString tabela,QString indice,QString novo){
expressao="UPDATE ";
expressao.append(tabela);
expressao.append(" SET nome=:novo WHERE codigo==:indice");
query.prepare(expressao);
query.bindValue(":novo",novo);
query.bindValue(":indice",indice);
query.exec();
}

When I do make this message come:

brevleq@brevleq:~/caixa$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.3.0/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.3.0/include/QtCore -I/usr/local/Trolltech/Qt-4.3.0/include/QtCore -I/usr/local/Trolltech/Qt-4.3.0/include/QtGui -I/usr/local/Trolltech/Qt-4.3.0/include/QtGui -I/usr/local/Trolltech/Qt-4.3.0/include/QtSql -I/usr/local/Trolltech/Qt-4.3.0/include/QtSql -I/usr/local/Trolltech/Qt-4.3.0/include -I. -Ibd -Itela_principal -Icadastro -Ilistagem/lista -Ilistagem/lista_tipos -Icriacao_caixa -I. -I. -o ManipulaTipos.o bd/ManipulaTipos.cpp
bd/ManipulaTipos.cpp: In member function 'void ManipulaTipos::adiciona(QString, QString, QString)':
bd/ManipulaTipos.cpp:15: error: no matching function for call to 'QSqlQuery::bindValue(const char [8], QString&)'
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:91: note: candidates are: void QSqlQuery::bindValue(const QString&, const QVariant&, QSql::ParamType)
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:92: note: void QSqlQuery::bindValue(int, const QVariant&, QSql::ParamType)
bd/ManipulaTipos.cpp:16: error: no matching function for call to 'QSqlQuery::bindValue(const char [6], QString&)'
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:91: note: candidates are: void QSqlQuery::bindValue(const QString&, const QVariant&, QSql::ParamType)
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:92: note: void QSqlQuery::bindValue(int, const QVariant&, QSql::ParamType)
bd/ManipulaTipos.cpp: In member function 'QList<QStringList> ManipulaTipos::listar(QString)':
bd/ManipulaTipos.cpp:29: error: invalid use of undefined type 'struct QVariant'
/usr/local/Trolltech/Qt-4.3.0/include/QtCore/qobject.h:45: error: forward declaration of 'struct QVariant'
bd/ManipulaTipos.cpp:30: error: invalid use of undefined type 'struct QVariant'
/usr/local/Trolltech/Qt-4.3.0/include/QtCore/qobject.h:45: error: forward declaration of 'struct QVariant'
bd/ManipulaTipos.cpp: In member function 'void ManipulaTipos::remove(QString, QString)':
bd/ManipulaTipos.cpp:43: error: no matching function for call to 'QSqlQuery::bindValue(const char [8], QString&)'
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:91: note: candidates are: void QSqlQuery::bindValue(const QString&, const QVariant&, QSql::ParamType)
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:92: note: void QSqlQuery::bindValue(int, const QVariant&, QSql::ParamType)
bd/ManipulaTipos.cpp: In member function 'void ManipulaTipos::atualiza(QString, QString, QString)':
bd/ManipulaTipos.cpp:52: error: no matching function for call to 'QSqlQuery::bindValue(const char [6], QString&)'
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:91: note: candidates are: void QSqlQuery::bindValue(const QString&, const QVariant&, QSql::ParamType)
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:92: note: void QSqlQuery::bindValue(int, const QVariant&, QSql::ParamType)
bd/ManipulaTipos.cpp:53: error: no matching function for call to 'QSqlQuery::bindValue(const char [8], QString&)'
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:91: note: candidates are: void QSqlQuery::bindValue(const QString&, const QVariant&, QSql::ParamType)
/usr/local/Trolltech/Qt-4.3.0/include/QtSql/qsqlquery.h:92: note: void QSqlQuery::bindValue(int, const QVariant&, QSql::ParamType)
make: ** [ManipulaTipos.o] Erro 1

I can't understand!! I looked 4 times in QT help and I think the sintax is correct!!

brevleq
1st November 2007, 11:47
I've solved the problem!!

I forgot include the QVariant Library!!

QInforaase
18th November 2013, 22:30
Thanks i had the same probleme and now i fixed it thanks to you :)