Good afternoon,

I guess it is more a c++ beginner's question than actually Qt releated. So it probably fits best here:

I want to access a MySql database. Everything is working fine. To get a better structure I wanted to have my database interactions in one class:

MyDatabase

Ok, so why not inherit from QSqlDatabase and extend with the needed additional members:

Qt Code:
  1. #ifndef MYDATABASE_H
  2. #define MYDATABASE_H
  3.  
  4. #include <QSqlDatabase>
  5.  
  6. class MyDatabase : public QSqlDatabase
  7. {
  8.  
  9. public:
  10. MyDatabase();
  11. };
  12.  
  13. #endif // MYDATABASE_H
To copy to clipboard, switch view to plain text mode 

If I now want to create a connection with:

Qt Code:
  1. mydb = MyDatabase::addDatabase("QMYSQL")
To copy to clipboard, switch view to plain text mode 

I get the message:

Qt Code:
  1. ./Stromverbrauch/mainwindow.cpp: In member function 'int MainWindow::connectDatabase()':
  2. ../Stromverbrauch/mainwindow.cpp:33:44: error: no match for 'operator=' in '((MainWindow*)this)->MainWindow::mydb = QSqlDatabase::addDatabase(const QString&, const QString&)((* & QString((*(const QLatin1String*)(& QLatin1String(QSqlDatabase::defaultConnection))))))'
  3. ../Stromverbrauch/mainwindow.cpp:33:44: note: candidate is:
  4. In file included from ../Stromverbrauch/mainwindow.h:25:0,
  5. from ../Stromverbrauch/mainwindow.cpp:1:
  6. ../Stromverbrauch/mydatabase.h:6:7: note: MyDatabase& MyDatabase::operator=(const MyDatabase&)
  7. ../Stromverbrauch/mydatabase.h:6:7: note: no known conversion for argument 1 from 'QSqlDatabase' to 'const MyDatabase&'
To copy to clipboard, switch view to plain text mode 

Ok, I have read somewhere in a different forum the advice to reimplement the "addDatabase" function.
But why is this necessary? Shoud the child not inheric also static functions?
What am I missing to understand the issue?

I am looking forward for your advice.

RogerWilco77