AlbertoN
24th October 2013, 11:35
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);
therefore my MyApp constructor is like this:
MyApp(Database *const m_db=0, QWidget *parent = 0);
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;
class Widget : public QWidget
{
public:
Widget(Database *const db, QWidget *parent = 0) : QWidget(parent), m_db(db) {}
private:
Database *const m_db;
};
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
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);
therefore my MyApp constructor is like this:
MyApp(Database *const m_db=0, QWidget *parent = 0);
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;
class Widget : public QWidget
{
public:
Widget(Database *const db, QWidget *parent = 0) : QWidget(parent), m_db(db) {}
private:
Database *const m_db;
};
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