Answer the question
In order to leave comments, you need to log in
Easiest way to call a function in QT?
When you click on a certain button, you need to perform a certain function (display a modal window, sort, delete, etc.), in general, the simplest event handling.
Do I understand correctly that the easiest way is to create a child class from QPushButton for each button, and define the corresponding slot (function) in it? Or is there an easier way?
Answer the question
In order to leave comments, you need to log in
Наследование стоит применять тогда, когда вам нужен доступ к состоянию и детальным событиям. Для обработки нажатия достаточно прицепить ваш обработчик на сигнал QPushButton::clicked
:
auto btn = new QPushButton("click me!");
QObject::connect(btn, &QPushButton::clicked, []() {
// создание диалога и вызов его в модальном режиме (через QDialog::exec)
});
//-----------------------------------
void myFoo() { }
auto btn = new QPushButton("click me!");
QObject::connect(btn, &QPushButton::clicked, myFoo);
auto btn = new QPushButton("click me!");
QObject::connect(btn, &QPushButton::clicked, []() {
::updateTable(table);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question