Results 1 to 4 of 4

Thread: Simplest SQL example

  1. #1
    Join Date
    Oct 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Simplest SQL example

    I want to do this:
    1. connect to an odbc database connection
    2. execute a query.
    3. exit my program

    Can anyone please show me how to do this simple task in QT?

  2. #2
    Join Date
    Sep 2009
    Posts
    20
    Thanked 2 Times in 2 Posts

    Default Re: Simplest SQL example

    Hi

    Please check sqlbrowser example, it's quite simple

  3. #3
    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: Simplest SQL example

    this is not a difficult thing. just c&p from the docs:
    Qt Code:
    1. #include <QtGui>
    2. #include <QtSql>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication app(argc, argv);
    7.  
    8. QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    9. db.setHostName("acidalia");
    10. db.setDatabaseName("customdb");
    11. db.setUserName("mojito");
    12. db.setPassword("J0a1m8");
    13. bool ok = db.open();
    14.  
    15. if(ok)
    16. {
    17. QSqlQuery query("SELECT country FROM artist");
    18. while (query.next())
    19. {
    20. QString country = query.value(0).toString();
    21. qWarning() << country;
    22. }
    23. }
    24.  
    25. return app.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

    By reading the docs about QSqlDatabase you should be able to connect via ODBC.

  4. The following user says thank you to Lykurg for this useful post:

    ajo (25th February 2013)

  5. #4
    Join Date
    Jul 2011
    Posts
    1
    Platforms
    Windows

    Default Re: Simplest SQL example

    Hi,

    I want to use qt sql component from plain c++ from visual studio.
    Can anyone please provide me sample for this?

    I could learn about qt's add-in for visual studio but as per my understanding that becomes managed code (This dependency on .net framework i don't want to add).

    I just want to use library (qt-sql) in my c++ project so i can access database from my application.

    Thanks in advance.

    Regards,
    Ujjwal

Similar Threads

  1. Replies: 1
    Last Post: 4th June 2009, 17:44
  2. Trying to Connect To SQL Server 2005
    By rossd in forum Installation and Deployment
    Replies: 0
    Last Post: 6th March 2009, 19:56
  3. SQL Drivers Distribution
    By kandalf in forum Installation and Deployment
    Replies: 1
    Last Post: 12th January 2009, 09:17
  4. Poor performance with Qt 4.3 and Microsoft SQL Server
    By Korgen in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2007, 10:28
  5. Can I use the Sql Module without chanage .pro file?
    By fengtian.we in forum Qt Programming
    Replies: 9
    Last Post: 21st May 2007, 10:59

Tags for this Thread

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.