Qt signals slots, cast type in new notation

c++, qt

Solution

This should work

connect(ui->comboBox, 
        static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
        ps,
        &PlotSystem::requestPlotsAvailable);

Qt 5.7 introduces `qOverload` (or QOverload for C++11) for convenience/readability:

connect(ui->comboBox, 
        qOverload<const QString &>(&QComboBox::activated),
        ps,
        &PlotSystem::requestPlotsAvailable);

See this question about pointers to overloaded functions

Problem

Given the following two: ``` connect(ui->comboBox, SIGNAL(activated(QString)), ps, SLOT(requestPlotsAvailable(QString))); connect(ui->comboBox, &QComboBox::activated, ps, &PlotSystem::requestPlotsAvailable); ``` The first uses the old notation, which works. The second uses the new notation and gives the error ``` error: no matching function for call to 'PlotSystemGui::connect(QComboBox*&, <unresolved overloaded function type>)' ``` How to avoid the error using the new notation?

Original source

Related problems