boost di QObject support.
Expected Behavior
we try to use boost di with QObject from another .so inside our main program using di::extension::runtime_injector.
Actual Behavior
we get error that not mentioned in boost di documentations.
Steps to Reproduce the Problem
https://github.com/mostafajalal20/Di_sample.git this is our example to showing the problem.
Any changes about this issue?
Im having the same issues.
I understand that this problem is due to having default value of QObject in constructor.
FooClass(int a, QObject parent = nullptr)
The class shown above causes problems in using boost. the below code shows correct form of above class.
FooClass(int a, QObject parent)
Thank you, this was one of the problems, but i did try to mend it as you described. But I also was able to realize another problem, which ended up being the solution for me.
QWidgets have their copy-, and move constructor deleted, meaning they cannot be copied or returned form functions either. So for example, the following code would throw an error:
class MyWidget : public QWidget {
//...
};
MyWidget createWidget(){
MyWidget widget;
return widget
//alternatively return std::move(widget);
}
int main(){
//...
MyWidget widget = createWidget();
widget.show();
//...
}
And i was trying to instantiate MyWidget the following way:
int main(){
//...
auto injector = di::make_injector()
injector.create<MyWidget>().show();
}
But this uses the move constructor, which is deleted in QWidget, so it kept throwing an error. But once i change it to some sort of pointer type (simplest example would be injector.create<MyWidget*>()->show()), it works perfectly.
This might be somewhat of a noob error, but i thought i post it maybe someone in the future will face the same.
Yes I used all arguments of constructors as std::shared_ptr because the boost::di work without any problem with raw or smart pointers.