I have the following class declaration:
class nets_list : public QDockWidget
{
Q_OBJECT
private:
QListView * files;
public slots:
void SelectNet(QModelIndex i);
signals:
void NetSelected(QString t);
public:
nets_list(QWidget * parent = nullptr);
};
At some point in my nets_list
constructor, I want to connect a clicked(QModelIndex)
signal of the files
member to the NetRunner(QString)
slot in the parent of my class:
bool x1 = connect(files, SIGNAL(clicked(QModelIndex)), this, SLOT(SelectNet(QModelIndex)));
bool x2 = connect(this, SIGNAL(NetSelected(QString)), parent, SLOT(NetRunner(QString)));
The code for SelectNet()
is just:
void nets_list::SelectNet(QModelIndex i)
{
emit NetSelected(fs->fileName(i));
}
because I just want to extract a QString
from the QModelIndex
parameter so that I can call the slot in the parent class.
The problem is that the second connect
call returns false (bool x2
appears to be false). Why?
Also: is there a better solution for connecting signals and slots with different parameter types? I thought that using an "intermediate" function such as my SelectNet(QModelIndex)
slot was a good solution.
EDIT:
the parent class is
class MW : public QMainWindow
{
Q_OBJECT
private:
QMenu * net_menu;
QMenuBar * menu_bar;
QStackedWidget * ctrl;
netBuilderWidget * builder;
netTrainerWidget * trainer;
netRunnerWidget * runner;
nets_list * nets_dock;
public slots:
void netBuilder();
void netTrainer();
void netRunner(QString t);
void addNet();
public:
MW();
QSize minimumSizeHint() const Q_DECL_OVERRIDE;
QSize sizeHint() const Q_DECL_OVERRIDE;
};
replace
SLOT(NetRunner(QString))
with
SLOT(netRunner(QString))
and the connect should work.