Search code examples
qtshared-ptr

Qt connect slot with signal from boost::shared_ptr


I have a mainwindow app, when shortcut is triggered, a dialog will popup to show some information, the user may do some configuration in this dialog, then a signal is sent back to the mainwindow, the mainwindow will do some further work. the pseudo code looks like this:

void MainWindow::actionConfigure_triggered()
{

    configureDialog = boost::shared_ptr<configure>(new configure(this));
    configureDialog->show();
    connect(configureDialog.get(), SIGNAL(reload()), this, SLOT(clean_reload()));
}

but when I triggered this function several times, segmentation fault happens. I use debugger to trace the execution, SIGSEGV received when executing boost::checked_delete function.

Any help will be highly appreciated! Thanks in advance. I just want the configure dialog to be created and deleted dynamically, or there are other better ways to implement this?


Solution

  • According to your backtrace the bug seems somewhere in destructor of configure and has little to do with the shared_ptr (except that it is the shared_ptr that calls the destructor) Check if there are double deletes of your object, if yes there is probably some other reference to it which is not a shared_ptr deleteing the object.