Quantcast
Channel: Installation and Deployment
Viewing all articles
Browse latest Browse all 22112

[SOLVED] Unable to connect to database..

$
0
0
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.

Viewing all articles
Browse latest Browse all 22112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>