Newbie here, I put a dock widget in a main window, and there is a button in this dock widget panel, now I want to connect, this button with a function defined in the main window, it threw out an error, what should I do? Thanks
connect
(
perfectPanel_->btn_AAA,
SIGNAL(clicked()),
this,
SLOT(on_actionAAA_triggered()),
Qt::UniqueConnection
);
Error message is
$PWD/ui_perfectPanel.h: In constructor ‘xixi::xixi()’:
$PWD/ui_perfectPanel.h:71:18: error: ‘QPushButton* Ui_perfectPanel::btn_AAA’ is inaccessible
$PWD/xixi/xixi.cpp:51:25: error: within this context
Note that I have already managed to connect this with a toolbar button in the main window (xixi.cpp), it works great.
This happens because your dock class,
perfectPanel, inherits privately from the generated ui classUi::perfectPanel:You could make that inheritance public, but shouldn’t. Instead you should make the signal part of the
perfectPanelclass, and route the internal signal from the button to that external signal:(And in case you would ask, yes, you can connect 2 signals together).
Then you simply connect the new signal inside your main window class: