You are not logged in.

bentm

Beginner

  • "bentm" is male
  • "bentm" started this thread

Posts: 8

Location: Odense, Denmark

Occupation: Vision Systems Engineer

  • Send private message

1

Tuesday, April 17th 2007, 9:13am

Automatic connections & inheritance

I have been making a class, which inherits from QMainWindow. It is going to be used as a framework for a series of applications in the company where I work. The h-file of the class contains an instance of the ui object:
-----------------------
protected:
Ui::CFrameworkClass ui;
-----------------------
and in the cpp file I set up the interface:
-----------------------
CFramework::CFramework(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
}
-----------------------

Now my question is the following: Is it possible to make an automatic connection between an action object which is declared in the interface class of the CFramework class, and a slot which is declared in a class which inherits from the CFramework class?

King Nak

Trainee

  • "King Nak" is male

Posts: 89

Location: Austria

  • Send private message

2

Tuesday, April 17th 2007, 9:35am

Should be possible, if you declare the slot as (pure) virtual, but I've
never tried something like this...
Let me know if it worked

bye
King Nak

bentm

Beginner

  • "bentm" is male
  • "bentm" started this thread

Posts: 8

Location: Odense, Denmark

Occupation: Vision Systems Engineer

  • Send private message

3

Tuesday, April 17th 2007, 10:00am

Hi

Thanks for the speedy answer. I dont know why I didn't think of that.
I tried it, and it works!

I might choose this solution, but Im not 100% satisfied with it. The thing is that I would like make as few changes to the 'baseclass' as possible. That is, I would like to avoid having to declare purely virtual members in the baseclass, when I need to make the other class act on a signal from the gui.
My idea is have a framework class that can be shared among serveral applications. To build upon this framework, the user adds buttons and actions to a local copy of the .ui file of the framework, and adds the handling of signals from these components in a class that inherits from the framework class. In this way I can update the functionality of the framework class without too much trouble, even though the class is used in several applications. I dont know whether it is possible, but it would be nice :o)

King Nak

Trainee

  • "King Nak" is male

Posts: 89

Location: Austria

  • Send private message

4

Wednesday, April 18th 2007, 7:55am

Ok, I don't know if I understood you correctely, so I will summarize what I think
you are doing:
1. You create a Framework class that will be used in many different applications
2. The specific application adds controls to that Base-Framework class by subclassing it
3. The original Base-Framework class should connect its signals to slots that are
not known in the base class, but should be defined in the sub-classes.

If this is right, I think there's a huge design-problem! One solution is, as I
mentioned beforehand, to add pure virtual slots to the base class.
The other one is, to connect the signals in the specific sub-class.
Otherwise you can't guarantee that the subclass will have the required slots.

However, it should be possible to connect to slots that are not defined yet, since
this is done in runtime and based on strings.

bye
King Nak

bentm

Beginner

  • "bentm" is male
  • "bentm" started this thread

Posts: 8

Location: Odense, Denmark

Occupation: Vision Systems Engineer

  • Send private message

5

Friday, April 20th 2007, 11:06am

I can see that my design might cause some problems, I might reconsider it.
But thanks for your answer anyway! :o)

/bentm