Reputation: 77
I'm struggling in figuring out how to use the connect function to recognize when the "x" button at the top left corner has been clicked. The red "x" button that cancels the window.
I know that I can override the closeEvent to do whatever I want but i need to use the connect function. Let me give you a background of the problem.
I have a function that I am calling from main like this:
ManageEmployeeWindow mng;
int choice = mng.checkChoice();
checkChoice is used to create the window and return an int depending on what button on that window that the user decides to click.
ex- If the user clicks button 1 then the checkChoice will return 1.
Now knowing that I would like to return a number through checkChoice using the connect function to recognize when the button is clicked, how can i do this when the "x" button is clicked?. Is there anyway of doing that?
Btw here is checkChoice just so you can understand what I mean with the connect.
int ManageEmployeeWindow::checkChoice(){
this->exec();
cout << "Inside of the checkChoice" << endl;
QEventLoop waitForResponse;
connect(ui->ManualEmployeeUpdate, SIGNAL (clicked()), &waitForResponse, SLOT(quit()));
connect(ui->DataIntegrationTool, SIGNAL (clicked()), &waitForResponse, SLOT(quit()));
connect(x,SIGNAL(clicked()),this,SLOT(ButtonPressed()));
waitForResponse.exec();
return choice;
}
Please let me hear your thoughts on this.
Thank you and my apoligies if I handed out too much detail
Upvotes: 0
Views: 1215
Reputation: 243955
If you want to create a signal when you press the X button you can create the signal and emit it in the closeEvent
method.
protected:
void closeEvent(QCloseEvent * event){
emit clicked();
event->ignore();
}
signals:
void clicked();
Upvotes: 0