PDA

View Full Version : Problem with Class and QSqlQuery , MacOS



davidpiedra
26th May 2010, 19:23
Hi, I create an application in Windows and works fine, now I'm trying to make it work on a mac with MacOS 10.4, with the proper adjustments the program is complied but I'm having problems with the database connection.

I'm trying to connect to a SQL Server database, I'm using de QODBC driver, the problem is that i'm trying to select from a table some information, but when I use a variable from a class I create the program stops working, but if I substitute the variable with a QString works fine.

This is the code that isn't working in the Mac, works fine in Windows.

QSqlQuery query ("Select * from table1 where name='" + obj.getName() + "'",db);

This is the code that works fine in Mac

QSqlQuery query( "Select * from table1 where name='Carlos'",db);

I if do this works fine too.


QString name = "Carlos";
QSqlQuery query( "Select * from table1 where name='" + name + "'",db);

Could this be a problem in the definition of the method getName in the class???

Lykurg
26th May 2010, 22:24
Have you debuged it? What does obj.getName() returns? Also you want have a look at QSqlQuery::prepare() to avoid SQL injection!

davidpiedra
27th May 2010, 15:37
First of all, Thanks for your reply and for the suggestion.

If I put obj.getName() in a QString variable, the variable gets the right value



QString name1 = obj->getName();

After this name's value is "Carlos" and if I use the varible name1 in the QsqlQuery line the result is the same, it won't work.

This is the definition of the method getName



QString Marca::getName(){
return hisname;
}


And hisname is a Qstring.

davidpiedra
2nd June 2010, 17:16
The error I'm getting is EXC_BAD_ACCESS.