1

Sorry for my English. I have some class.

class AdaptedWidget: public QWidget
{
    Q_OBJECT
public:
    AdaptedWidget(AdaptedWidget *parent = 0) {nothing}
    bool event(QEvent *event);
};

bool WindowManager::eventFilter(QObject *target, QEvent *event)
{
    auto window = qobject_cast<AdaptedWidget*>(target);
    **auto windowSharedPtr = std::make_shared<AdaptedWidget>(window);** //Error 
    ...

I need create from AdaptedWidget* smart pointer. I need to override the copy constructor? Or is the problem in the enforcement types?

Tipok
  • 675
  • 8
  • 26
  • 4
    shared_ptr and Qt's parent child relationships don't go well together. In your example, both the parent object and the shared_ptr would own the object,v and crash if the parent deletes the child before the shared_ptr. – Frank Osterfeld Dec 17 '16 at 12:34
  • @MikeI get the widget on which an event was committed. Widgets I have found in the stack.`std::stack>`. All the functions I work with std :: shared_ptr . And I need to translate QObject * to std :: shared_ptr . – Tipok Dec 17 '16 at 12:41
  • 1
    @nax , Are you trying to create a new `AdaptedWidget` every time an event is received in your *watched* window? – Mike Dec 17 '16 at 12:47
  • @Mike http://stackoverflow.com/questions/41188135/learn-about-occurred-events-from-other-class. Not new, they are contained in a stack. I'm getting the right to which was a click. And I need to make it a smart pointer for further work. – Tipok Dec 17 '16 at 12:54
  • 1
    @nax , why don't you compare each smart pointer from the your stack with the `window` that you get in the `eventFilter` function(using [`std::shared_ptr::get`](http://en.cppreference.com/w/cpp/memory/shared_ptr/get)), after that you can use the smart pointer that you already have in your stack, and do whatever you want with it. – Mike Dec 17 '16 at 22:41
  • 1
    @nax , in your current code, `std::make_shared` creates a new `AdaptedWidget` object with `window` being its parent, and then creates a smart pointer that holds this newly created object. This is absolutely not what you meant to do. – Mike Dec 17 '16 at 22:44

0 Answers0