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

I have experience with C ++, but I have never used Qt before. I am trying to connect to a SQLite database, so I found a tutorial here and am going with this. In the QtCreator IDE, I went to Add New -> C ++ Class, and in the header file inserted in the header, the header from this link and in the .cpp file 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 get this error:

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

Can someone point me in the right direction? I know that the "copypaste" code is not very good, I just wanted to know if I can work with DB communication, and I realized that something like this would be easy ... thanks for the help.

+3
1

DatabaseManager :

DatabaseManager db;

db, DatabaseManager, ();

+7

Source: https://habr.com/ru/post/1749328/


All Articles