nprogram’s blog

気ままに、プログラミングのトピックについて書いていきます

Qt SIGNALとSLOTについて

SIGNALの説明やSLOTの説明は、以下のサイトに記載してあります。 https://blog.qt.io/jp/2010/07/20/create-signals-and-slots-2/

connect 関数

  • connect(sender, SIGNAL(signal), receiver, SLOT(slot) );
    • sender : 信号が発生する部品のアドレスを渡す
    • SIGNAL(signal) : signal に信号とする関数を渡す
    • receiver : 信号を受け取る部品のアドレスを渡す
    • SLOT(slot) : 信号を受け取った際に呼び出す関数を渡す

connect関数の使い方

#include "mainwindow.h"
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QPushButton* button = new QPushButton("Quit");
    QObject::connect(button, SIGNAL( clicked() ),
            &app, SLOT(quit()) );
    button->show();
    return app.exec();
}