Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [SOLVED] Unable to connect to database..
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Unable to connect to database..

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fatihAyt3kin
    wrote on 26 Jan 2013, 12:27 last edited by
    #1

    Hi everybody!

    I have been struggling with this database connection problem for two days, and still couldn't find the correct way to fix it. This is the error I keep getting whenever I try to build my project. I know that I have to add QT += sql to my .pro file, but it didn't cure my problem either.

    error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall QSqlDatabase::open(void)" (_imp?open@QSqlDatabase@@QAE_NXZ) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)

    this is my main.cpp:
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    #define Path_to_DB ".../Documents/uniquePaper/accounts.sqlite"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    myDB = QSqlDatabase::addDatabase("QSQLITE");
    myDB.setDatabaseName(Path_to_DB);
    QFileInfo checkFile(Path_to_DB);
    
    if(checkFile.isFile())
    {
        if(myDB.open())
        {
            ui->result->setText("Connected to the database...");
        }
    
    }else
    {
        ui->result->setText("Database file is not found!...");
    }
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @

    and this is the header file:

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QDebug>
    #include <QFileInfo>
    #include <QtSql/QSqlDatabase>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void on_MainWindow_iconSizeChanged(const QSize &iconSize);

    private slots:

    private:
    Ui::MainWindow *ui;
    QSqlDatabase myDB;
    };

    #endif // MAINWINDOW_H
    @

    any suggestions?

    Thanks.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goblincoding
      wrote on 26 Jan 2013, 15:12 last edited by
      #2

      Is your library path set correctly?

      http://www.goblincoding.com

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fatihAyt3kin
        wrote on 26 Jan 2013, 15:16 last edited by
        #3

        Hey, thanks for the reply! By default, the program was running in debug mode and I changed to release mode which fixed the problem now. I guess it has something to do with sqldrivers plugin.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goblincoding
          wrote on 26 Jan 2013, 15:34 last edited by
          #4

          Mmmm...your project settings must be different for debug and release then as it really shouldn't matter otherwise which mode you run in.

          However, if you are happy with your solution, please mark the thread as "Solved" :)

          http://www.goblincoding.com

          1 Reply Last reply
          0

          1/4

          26 Jan 2013, 12:27

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved