Working with different buttons type
-
template <typename Control> void AddQLabel(QLabelStruct* qls, Control* control) { QLabel* label = new QLabel(qls->text, control); // <-- this works //.... } void AddQLabel(QLabelStruct* qls, QObject* control) { QLabel* label = new QLabel(qls->text, control); // <-- fails because of control type //... } Main::Main(QWidget* parent) : QMainWindow(parent) { ui.setupUi(this); QObject* btn = qobject_cast<QToolButton*>(ui.toolButton); AddQLabel(&qls, btn); // <-- fail cant use QOBject on new QLabel AddQLabel(&qls, ui.toolButton); // <-- works }Is it possible to write such a function that could work with button, toolbutton, checkbox, etc
without using a template? -
template <typename Control> void AddQLabel(QLabelStruct* qls, Control* control) { QLabel* label = new QLabel(qls->text, control); // <-- this works //.... } void AddQLabel(QLabelStruct* qls, QObject* control) { QLabel* label = new QLabel(qls->text, control); // <-- fails because of control type //... } Main::Main(QWidget* parent) : QMainWindow(parent) { ui.setupUi(this); QObject* btn = qobject_cast<QToolButton*>(ui.toolButton); AddQLabel(&qls, btn); // <-- fail cant use QOBject on new QLabel AddQLabel(&qls, ui.toolButton); // <-- works }Is it possible to write such a function that could work with button, toolbutton, checkbox, etc
without using a template? -
@n34rt said in Working with different buttons type:
void AddQLabel(QLabelStruct* qls, QObject* control)
use QWidget instead.