QPlace
4th August 2007, 12:37
Moc returns error when slot is declared as a templated function.
I have following situation - my slots are different only in return type. So, following examples of MDI in QT docs I am creating two functions per each action. Example:
void newView(); // slot that is triggered by a menu action
View* createView(); // actual creation of a View.
If I have, say 10 of such different view types, the code becomes too cluttered. I don't want to move "creatView" code in "newView", since "createVeiw" calls will be reused elsewhere.
Question: is there a possibility to somehow employ templates here and do not revert to doing something like:
void newView(int viewtype)
{
switch (viewtype)
{
BaseView* view;
case 1: view = (BaseView*) createView1();
case 2: view = (BaseView*) createView2();
...
}
}
I have following situation - my slots are different only in return type. So, following examples of MDI in QT docs I am creating two functions per each action. Example:
void newView(); // slot that is triggered by a menu action
View* createView(); // actual creation of a View.
If I have, say 10 of such different view types, the code becomes too cluttered. I don't want to move "creatView" code in "newView", since "createVeiw" calls will be reused elsewhere.
Question: is there a possibility to somehow employ templates here and do not revert to doing something like:
void newView(int viewtype)
{
switch (viewtype)
{
BaseView* view;
case 1: view = (BaseView*) createView1();
case 2: view = (BaseView*) createView2();
...
}
}