Results 1 to 3 of 3

Thread: Connect to an existing SQL Server Database

  1. #1
    Join Date
    Jul 2015
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Unhappy Connect to an existing SQL Server Database

    Hi , i want to use an existing database from my project , but i don't know how.
    I used QSqlDatabase, but no good result.
    How to do it ??

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,336
    Thanks
    36
    Thanked 1,529 Times in 1,480 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Connect to an existing SQL Server Database

    Show the code you have.
    Nobody can help you fix a problem if nobody can look what the problem might be.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    18
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Connect to an existing SQL Server Database

    you can connect to database with following code:
    #include "mainwindow.h"
    #include <QApplication>
    #include <QtSql>
    #include <QMessageBox>

    bool createConnection()
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("my driver QPSQL");
    db.setHostName("");
    db.setDatabaseName("my testdb");
    db.setUserName("");
    db.setPassword("");

    if (!db.open()) {
    QMessageBox::warning(0, QObject::tr("Database Error"),
    db.lastError().text());
    return false;
    }
    return true;
    }

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    if (!createConnection())
    return 1;

    MainWindow form;
    form.resize(500, 600);
    form.show();
    return app.exec();
    }

Similar Threads

  1. Replies: 1
    Last Post: 19th June 2015, 14:09
  2. Replies: 15
    Last Post: 11th March 2014, 01:54
  3. Replies: 5
    Last Post: 27th January 2014, 22:22
  4. Encrypting an existing sqlite database in sqlcipher
    By thefatladysingsopera in forum Newbie
    Replies: 5
    Last Post: 21st October 2011, 18:47
  5. Replies: 3
    Last Post: 8th March 2011, 07:57

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.