Automating a custom QGraphicsObject control in an external QT based process - qt

I have injected a DLL into an external application that is based on the QT framework. I then use the command QApplication::allWidgets() and iterate through the list of widgets to find a QGraphicsView that represents the window I want to interact with. The buttons and other controls in the scene are all derived from QGraphicsObject. I don't have the source, so I can only cast to QGraphicsObject and not the actual type. The list of methods from the metaobject is incomplete, which is to be expected, because I cast to a QGraphicsObject. I can find the method names using IDA though. Is it possible to call a particular method, and how would you do it?

Related

Livereload after save but keep some objects

Livereload for development purposes: after save the application should reload the GUI entirely.
But there are some C++ objects (used in QML code) that should stay and find themselves in the new version of the GUI.
Possible approach is to add to such object a string property that will be the same in the newely-loaded QML code, so it'll attach to that. Obviously, the object has two parts: the QObject and Qt-independent implementation.
There is a problem with that: the other bindings need such object to be already attached. These signals/properties mustn't arrive earlier.
I'm thinking about setting that 'persist' property in the Component.onCompleted, so it'll be like atomic with the C++ constructor. Will it work? Other suggestions? How do you do it?

Complex initialization in Custom QML type

I am creating a C++ class that will be registered as a QML type. I want to run some non-trivial logic when the object is initialized. I don't want to put this logic in the constructor because that is bad practice. In a standard C++ class I would usually create a Startup() function with this logic and call it just after initializing the object, but I have no control over this as objects are initialized in QML.
How should I implement this custom initialization logic for a custom QML type?
For those who want the details. I am making a QAbstractListModel that keeps track of all .txt files in a directory. When it is created it will scan the directory (passed in via property) and update its internal collection with the names of all .txt files in that directory.
Edit1: After looking at Qt's example projects I found that many of them actually do all initialization logic in the constructor, including things like setting up DB connections and doing an initial DB query and query parsing. One need only search for "database" from the Qt Creator Welcom->Examples screen to see these samples. I would appreciate it if someone found and explained a better way.

Communication between multiple dialogs in Qt, using signals and slots or references

Im developing a Qt GUI application, with multiple QDialog's open at any given time.
These dialogs need to communicate and notify with each other when special data is received on a separate network thread.
Usually a dialog will hold a reference to at least one other dialog, and thus can communicate using this.
My question is whether to use this reference to call a function in a another dialog, or emit a signal and absorb that signal in a slot in another dialog? Im aware that this might be a preference - but I would still like to get some input on this.
I suggest you start by looking at Qt's Model View Programming. Based on the Model View Controller design pattern, you would be better off separating data (the model) and the view of that data.
If you follow Qt's Model View Programming, you'll find that when the model containing your data changes, the view(s) are notified and react accordingly. You shouldn't need to message from one dialog to another.

Qt Design Promoted Qpushbutton parameterised constructor

I've been learning about subclassing and widget promotion in Qt Designer and I've promoted some QPushButtons. My promoted class represents the number keys on a calculator, and takes a parameter in the constructor. The parameter given is the number of the button and it is passed in as an int.
Is there a way to tell Qt Designer how to construct each button? The constructor needs the numbers 0-9 passed to it. If I manually modify the generated code it works; however, each time it generates the form, I have to manually edit it.
There is no simple way to achieve this while keeping your argument in the constructor I'm afraid (read this page in the docs to how you might go about it).
I think your best solution is to keep the constructor mirroring that of QPushButton (i.e. just passing a parent QWidget) and set your custom data by calling a function afterwards.

QGrahicsItem and their children

I have now tried for hours to make sense of how QGraphicsItem behaves with respect to children. I create a new QGraphicsItem B (actually an own subclass of it), and then add it to another QGraphicsItem A as child by invoking the setParentItem method on B. Immediately after that A has B as child. I have verified with some debug code that iterates over the children of A. Then A is added to a List of As in a Manager. Some time later in the program, in a QWidget the lists iterator is obtained from the manager. I then iterate over the list of As and check the children for each of them and all of them are gone. I have verified in the debugger that the Manager is really the same instance and the list is also the same instance. Somehow this really puzzles me, who in the Qt FWK decides for me that my A objects do no longer need their children?
I'm a newby to Qt and C++, also with extensive development experience from java to objective-c so I have some hope it is a speciality of Qt I'm not aware of, not entirely my own stupidity...
Best Regards,
André
FYI:
QGraphicsItemGroup specially designed for grouping.
// Group all selected items together
QGraphicsItemGroup *group = scene->createItemGroup(scene->selecteditems());

Resources