Question

The code below is outputting the following error :

error C2663: 'boost::signal0<R,Combiner,Group,GroupCompare,SlotFunction>::connect' : 2 overloads have no legal conversion for 'this' pointer
        with
        [
            R=void,
            Combiner=boost::last_value<void>,
            Group=int,
            GroupCompare=std::less<int>,
            SlotFunction=boost::function<void (void)>
        ]

Here is the code :

RepositoryEditor::RepositoryEditor(const boost::signal<void ()>& scenarioHasChangedSignal, QWidget* parent)
    : QDialog(parent),
    m_pActionRemove(new QAction(this))
{
    ui.setupUi(this);

    m_pActionRemove->setText("Remove");
    m_pActionRemove->setToolTip("Remove this device");

    connect(m_pActionRemove , SIGNAL(triggered()),this, SLOT(onActionRemoveClicked()));
    connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(onButtonClicked(QAbstractButton *)));
    connect(ui.treeWidgetDevicesList, SIGNAL(itemSelectionChanged()), this, SLOT(onItemSelectionChanged()));
    connect(this, SIGNAL(itemRemovedFromTree(const Events::VCS::PnPDevice &)), RepositoryManager::getInstance().getRepository(), SLOT(removeDevice(const Events::VCS::PnPDevice &)));
    connect(RepositoryManager::getInstance().getRepository(), SIGNAL(deviceAdded(const DeviceItem &)), this, SLOT(addItemInTree(const DeviceItem &)));
    connect(RepositoryManager::getInstance().getRepository(), SIGNAL(deviceUpdated(const DeviceItem &)), this, SLOT(updateItemInTree(const DeviceItem &)));

    scenarioHasChangedSignal.connect(boost::bind(&RepositoryEditor::updateAllRootItem, this));

    this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
    this->setAttribute( Qt::WA_DeleteOnClose, true );

    initTreeView();
}

void RepositoryEditor::updateAllRootItem()
{
    int index = ui.treeWidgetDevicesList->topLevelItemCount();
    for (int i=0;i<index;i++) 
    {
        RootItem rootItem = (ui.treeWidgetDevicesList->topLevelItem(i))->data(0,Qt::UserRole).value<RootItem>();
        (ui.treeWidgetDevicesList->topLevelItem(i))->setText(0,"test");

    }
}

The question is : How to use bind function with "this" pointer?

thank you

Was it helpful?

Solution

It says that scenarioHasChangedSignal is const, whereas connect is a non-const member function, which can not be called on a const object. Declare scenarioHasChangedSignal as non-const boost::signal<void ()>&.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top