tags:

views:

89

answers:

1

I have experience with C++ but I've never really used Qt before. I'm trying to connect to a SQLite database, so I found a tutorial here and am going with that. In the QtCreator IDE, I went to Add New --> C++ Class and in the header file pasted in the header the header from that link and in the .cpp file I pasted the source. My main.cpp looks like this:

#include <QtGui/QApplication>
#include "mainwindow.h"
#include "databasemanager.h"
#include <qlabel.h>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    DatabaseManager db();
    QLabel hello("nothing...");
    if(db.openDB()){    // Line 13

        hello.setText("Win!");
    }

    else{
        hello.setText("Lame!");
    }
    hello.resize(100, 30);

    hello.show();

    return a.exec();
}

And I'm getting this error:

main.cpp:13: error: request for member 'openDB' in 'db', which is of non-class type 'DatabaseManager()'

Can anyone point me in the right direction? I know "copypaste" code isn't good, I just wanted to see if I could get DB connectivity working and I figured something like this would be simple... thanks for the help.

+4  A: 

Change the DatabaseManager line to:

DatabaseManager db;

You're declaring a local function called db that takes no parameters and returns a DatabaseManager object when you provide the ();

RC
Tried this earlier and ended up with:main.cpp:11: undefined reference to `DatabaseManager::DatabaseManager(QObject*)'
Airjoe
That looks like a link error. Make sure you're linking in the QT library.
RC
Its not a link error, its saying there is no constructor defined for those arguments.
Akusete
I'm sorry, what exactly do you mean by linking in the QT library? I have included my header file in main.cpp. Do I have to do something special in QtCreator to link? I'm just doing Build All.
Airjoe
Excellent, adding a constructor and destructor in my source file fixed the errors. Having other logical problems (it thinks it's opening the db but the db doesn't exist...) but I'll give that a whack on my own. Thanks to all of you!
Airjoe