Joseph
Joseph

Reputation: 13178

Qt 101: Why can't I use this class?

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.

Upvotes: 3

Views: 857

Answers (1)

RC.
RC.

Reputation: 28207

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 ();

Upvotes: 7

Related Questions