Sorry for reanimating old thread:)

I was looking at QAction code and didn't see big dependecies on qtwidgets.

Isn't possible to implement this solution, keeping source and binary 
compatibility:

We add QGuiAction to QtGui module. It has exact API like current QAction (which 
is discussable, but it's not my main idea) except it doesn't have 
associatedWidgets method. Instead, it have assotiatedObjects method and stores 
abstract QObjects (which are QWidgets, QGraphicsWidgets or QML items).

QAction becomes a simple wrapper around QGuiAction and adds associatedWidgets 
method which looks like this:

QList<QWidget*> associatedWidgets() 
{
     QList<QWidget*> result;
     foreach (QObject *object, assotiatedObjects()) {
          if (QWidget *w = qobject_cast<QWidget *>(object) )
              result.append(w);
     }
     return result;
}

The next thing to fix - is ~QAction(), it should remove itself from added 
objects.
I suggest to use destroyed(QObject*) signal and move that code into the QWidget 
itself.
Second solution is to send RemoveAction event to objects.
Third solution requires RTTI - we can add c++ interface to a QWidgetPrivate 
that allows to remove actions from it and use dynamic_cast to cast object's 
d_ptr to that interface (hack, yeah)

I prefer signal, anyway - it' widget's problems to track objects it refers too. 
And in most cases QWidgets becomes deleted before it's Actions.

Advantages - current code keeps working, no breaking compatibility we can write 
code that is not dependent on the QWidgets and share between qml/widgets code.
Disadvantages - QAction will work a bit slower.

Иван Комиссаров

_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to