Hi all,
I have this scenario:
I created a custom Database class, then I create an instance of it in main.cpp and i pass it across my app as a const pointer:
Database *const m_db = new Database();
m_db->createTables();
m_db->exampleData();
MyApp(m_db);
Database *const m_db = new Database();
m_db->createTables();
m_db->exampleData();
MyApp(m_db);
To copy to clipboard, switch view to plain text mode
therefore my MyApp constructor is like this:
MyApp
(Database
*const m_db
=0,
QWidget *parent
= 0);
MyApp(Database *const m_db=0, QWidget *parent = 0);
To copy to clipboard, switch view to plain text mode
Now I need to pass the Database pointer to a promoted widget. Is it possible?
When I try to do that I get an error as in designer Database class is not known, but as my pointer is const I can't call a
member method to set it, but rather I have to use a member initializer list, something like:
class Database;
{
public:
Widget
(Database
*const db,
QWidget *parent
= 0) : QWidget(parent
), m_db
(db
) {}
private:
Database *const m_db;
};
class Database;
class Widget : public QWidget
{
public:
Widget(Database *const db, QWidget *parent = 0) : QWidget(parent), m_db(db) {}
private:
Database *const m_db;
};
To copy to clipboard, switch view to plain text mode
Is there any other option except to lose principle of least privilege or avoid using promoted widgets?
I tried googling, but I didn't find anything.
Thanks all
Bookmarks