본문 바로가기
C++ 200제/코딩 IT 정보

Qt QDialogButtonBox connect 이벤트 예제 소스, signal slot emit

by vicddory 2019. 2. 21.

Qt QDialogButtonBox connect 이벤트 예제 소스, signal slot emit 


  • Qt Designer - Buttons - Button Box


QDialogButtonBox connect signal


위 그림처럼 『Button Box를 ui에 추가』했을 때 이벤트 설정하는 방법입니다.


Qt5 이전, 이후 버전으로 구현 소스를 나눌 수 있습니다.




Qt5 이전 버전


1
2
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
cs


connect는 다들 아시다시피 Qt5.3 이후로 획기적인 변화가 생겼죠. 그래서 Qt5 이전 버전을 쓰신다면 위와 같이 예전 스타일로 사용하시면 됩니다.


Qt5 이상 버전


1
2
connect(buttonBox, &QDialogButtonBox::accepted, this, [=](){ qDebug("ok or save"); });
connect(buttonBox, &QDialogButtonBox::rejected, this, [=](){ qDebug("cancel"); });
cs


Qt5 이상 버전이라면 위와 같이 람다를 섞어서 사용해 볼 수 있네요.


다이얼로그 버튼 박스는 Qt에서 자주 사용되는 위젯이니 간단한 사용 방법 미리 알아두세요.


 Qt QDialogButtonBox connect 이벤트 예제 소스, signal slot emit

댓글