Results 1 to 4 of 4

Thread: Problem with Class and QSqlQuery , MacOS

  1. #1
    Join Date
    Feb 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with Class and QSqlQuery , MacOS

    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.
    Qt Code:
    1. QSqlQuery query ("Select * from table1 where name='" + obj.getName() + "'",db);
    To copy to clipboard, switch view to plain text mode 

    This is the code that works fine in Mac
    Qt Code:
    1. QSqlQuery query( "Select * from table1 where name='Carlos'",db);
    To copy to clipboard, switch view to plain text mode 

    I if do this works fine too.
    Qt Code:
    1. QString name = "Carlos";
    2. QSqlQuery query( "Select * from table1 where name='" + name + "'",db);
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problem with Class and QSqlQuery , MacOS

    Have you debuged it? What does obj.getName() returns? Also you want have a look at QSqlQuery::prepare() to avoid SQL injection!

  3. #3
    Join Date
    Feb 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with Class and QSqlQuery , MacOS

    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

    Qt Code:
    1. QString name1 = obj->getName();
    To copy to clipboard, switch view to plain text mode 
    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

    Qt Code:
    1. QString Marca::getName(){
    2. return hisname;
    3. }
    To copy to clipboard, switch view to plain text mode 

    And hisname is a Qstring.

  4. #4
    Join Date
    Feb 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with Class and QSqlQuery , MacOS

    The error I'm getting is EXC_BAD_ACCESS.

Similar Threads

  1. MacOs deployment problem (QT 4.6.2)
    By Annihilator in forum Installation and Deployment
    Replies: 1
    Last Post: 3rd April 2010, 15:28
  2. Ibase plugin problem under MacOs 10.4
    By giandrea77 in forum Installation and Deployment
    Replies: 1
    Last Post: 30th January 2009, 18:11
  3. MacOS and ibase compilation problem
    By giandrea77 in forum Qt Programming
    Replies: 0
    Last Post: 20th January 2009, 13:04
  4. Installation problem of Qt 4.4.2 in MACOS Leopard-Intel
    By santosh.kumar in forum Installation and Deployment
    Replies: 0
    Last Post: 3rd October 2008, 12:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.