c++ - Qt: "No such signal" error -
i have simple code; here i've 2 buttons, press first 1 , shows msgbox. press "okay", , should call connected action written in second button, doesn't. instead error:
object::connect: no such signal qmessagebox::buttonclicked(qmessagebox::ok) object::connect: (receiver name: 'openfile_bttn')
the code:
#include "mainwindow.h" #include "ui_mainwindow.h" mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow) { ui->setupui(this); } mainwindow::~mainwindow() { delete ui; } void mainwindow::on_openfile_bttn_clicked(){ qfiledialog::getopenfilename(this,tr("open file"), "", tr(""));//open dialog "openfile" } void mainwindow::on_pushbutton_clicked(){ qmessagebox msgbox; msgbox.settext("push button choose file"); //connect clicking button in msgbox action in openfile_bttn button qwidget::connect(&msgbox,signal(buttonclicked(qmessagebox::ok)), ui->openfile_bttn, slot(on_openfile_bttn_clicked())); msgbox.exec();//show msgbox }
also found interesting thing, error message appears when msgbox popup, not when click button "ok" inside msgbox.
no need signals here, exec returns button clicked.
void mainwindow::on_openfile_bttn_clicked(){ qfiledialog::getopenfilename(this,tr("open file"), "", tr(""));//open dialog "openfile" } void mainwindow::on_pushbutton_clicked(){ qmessagebox msgbox; msgbox.settext("push button choose file"); //connect clicking button in msgbox action in openfile_bttn button if(msgbox.exec() == qmessagebox::ok) { on_openfile_bttn_clicked(); } }
if want use custom buttons can still call msgbox.buttonclicked()
after exec find out button clicked.
Comments
Post a Comment