
GenderGender::connect 함수는 Qt 프레임워크의 Signal-Slot 메커니즘을 이용한 연결 함수입니다.
이 함수는 두 개의 객체 간의 Signal-Slot 연결을 설정하는 역할을 합니다.
예를 들어, 버튼을 클릭했을 때 발생하는 시그널을 받고, 그 시그널을 처리하는 슬롯 함수를 연결하는 경우에 사용됩니다.
사용법은 다음과 같습니다.
#hostingforum.kr
cpp
connect(sender, SIGNAL(signalName()), receiver, SLOT(slotFunction()));
- sender: 시그널을 발생시키는 객체
- SIGNAL(signalName()): 발생하는 시그널 이름
- receiver: 슬롯 함수를 호출하는 객체
- SLOT(slotFunction()): 호출할 슬롯 함수 이름
예제 코드는 다음과 같습니다.
#hostingforum.kr
cpp
QPushButton *button = new QPushButton("클릭");
QLabel *label = new QLabel("클릭한 횟수");
int count = 0;
connect(button, &QPushButton::clicked, this, [this, &label]() {
count++;
label->setText(QString("클릭한 횟수: %1").arg(count));
});
이 예제 코드에서는 QPushButton을 클릭했을 때 발생하는 시그널을 QLabel의 텍스트를 업데이트하는 슬롯 함수로 연결합니다.
2025-07-04 02:02