I've seen other people with this issue, but I can't find a solution that has worked. I've had MySQL downloaded for a while, and use it for web development, but this is my first time trying to hook it up with Qt.
This is my main.cpp
file:
#include "mainwindow.h"
#include "passwords.h"
#include "signup.h"
#include <QApplication>
#include <QWidget>
#include <QtSql>
#include <QDebug>
#include "qsqldriver.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString servername = "LOCALHOST//QMYSQL";
QString dbname = "test";
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setConnectOptions();
QString dsn = QString("DRIVER={SQL Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername) .arg(dbname);
db.setDatabaseName(dsn);
if(db.open()){
qDebug() << "Opened";
db.close();
}
else{
qDebug() << "Error =" << db.lastError().text();
qDebug ( ) << QSqlDatabase :: drivers ( );
}
MainWindow w;
w.show();
return a.exec();
}
I've included the following in my .pro
file:
INCLUDEPATH += /Users/tomeldridge/downloads/mysql-5.6.17-osx10.7-x86_64/include
INCLUDEPATH += /Users/tomeldridge/downloads/mysql-5.6.17-osx10.7-x86_64/lib
INCLUDEPATH += /Applications/XAMPP/xamppfiles/htdocs/xampp/sqlite/include
INCLUDEPATH += /Applications/XAMPP/xamppfiles/htdocs/xampp/sqlite
I get the error: QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
If I use SQLite, I get the error: Error: out of memory opening database
I have tried building the driver from scratch using the code from the Qt documentation:
-no-sql-<driver> ... Disable SQL <driver> entirely.
-qt-sql-<driver> ... Enable a SQL <driver> in the Qt Library, by default
none are turned on.
-plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to
at run time.
Possible values for <driver>:
[ db2 ibase mysql oci odbc psql sqlite sqlite2 tds ]
This apparently requires you to have downloaded the Qt Source Code, which I went and did, so you can use Qt Configure. Something went wrong along the way, and the commands I tried to use in terminal didn't work.
I also tried moving copies of the MySQL lib
files into the Qt lib
directory, since I saw someone who that worked for, but I didn't have any luck.
I've done several things to try and get this to work, and I've hooked up MySQL before, but I've wasted two days trying to get a database running, so any help would be awesome.
Aucun commentaire:
Enregistrer un commentaire