1

In my application I am using a QSqlDatabase to store some information. I did built it successfully with the following command (no errors even with verbose=3):

macdeployqt AppName.app/ -dmg -qmldir=~/dev/AppName/qml

Before that I successfully installed mysql55 using port

sudo port install mysql55

If I try to run my application it does not crash, but it also does not anything which involves database access.

This is my code for opening a database etc:

#include <QSqlQuery>
#include <QSqlDriver>

const QString DATABASE_NAME = "com.company.program.db";

MyClass::MyClass(QObject *parent) : QObject(parent) {
    mDB = QSqlDatabase::addDatabase("QSQLITE");

    #ifdef Q_OS_LINUX
    QString path(QDir::home().path());
    path.append(QDir::separator()).append(DATABASE_NAME);
    path = QDir::toNativeSeparators(path);
    mDB.setDatabaseName(path);           // NOTE: We have to store database file into user home folder in Linux
    #else
    mDB.setDatabaseName(DATABASE_NAME);  // NOTE: File exists in the application private folder, in Symbian Qt implementation
    #endif

    bool notOpened = !mDB.open();

    QMessageBox::critical(0, "MyClass", mDB.lastError().databaseText()); // always is 'out of memory'

    if (notOpened) emit failedToOpen();
    else {
        // some initialization
    }
}

MyClass::~MyClass() {
    mDB.close();
}

Has anyone experienced the same issues / a fix for this one?

Note: I am using Mac OS X 10.9 and Qt5.3.2

11
  • after open is failed, try to get and check the error message by calling mDB->lastError()->databaseText() Commented Oct 2, 2014 at 8:46
  • Strange thing is it does not emit the signal failedToOpen Commented Oct 2, 2014 at 9:18
  • Get the error message just after if (!mDB.open()) in the code Commented Oct 2, 2014 at 9:20
  • @N1ghtLight I get 'out of memory' exception. How can this happen? I have got only 2 tables, which do not have any entries at the beginning. Commented Oct 6, 2014 at 7:06
  • Niklas, search engine should be your best friend ... stackoverflow.com/a/18325616/2266412 Commented Oct 6, 2014 at 7:10

2 Answers 2

0

The Database Drivers are loaded at run-time. You won't get any database-config related errors during the compilation process, if the db-driver paths' are not correct. The paths' can't even be incorrect, as you build on a machine where Qt is installed.

On Windows this occurs often, when the exe can't access files in plugins\sqldrivers. Is there something like Linux's 'strace' on MAC? If yes, you could trace, in which paths your exe attempts to find driver plugins.

I always copy the entire plugin directory in installer and deploy it in the root-directory of the executable e.g. C:\Program Files (x86)\\plugins

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

I am on OS X and macdeployqt is doing all the stuff like copying the right directories ;)
0

I managed to fix the out of memory error by executing this code:

#ifdef Q_OS_MAC
    QString databaseName = QApplication::applicationDirPath().append("/").append(DATABASE_NAME);
    mDB.setDatabaseName(databaseName);
#endif

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.