Show message when close program in Qt/C++ [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Qt - c++
Show message when user close program
Thanks

Most general is to connect the aboutToQuit signal to a slot -- but as the docs say
The signal is particularly useful if
your application has to do some
last-second cleanup. Note that no user
interaction is possible in this state.
so if you need to show your message in Qt (so the main event loop must still be running) this won't work. In that case, I'd connect lastWindowClosed (and maybe also set quitOnLastWindowClosed to false, depending on your exact needs). If your app also ends in other ways (buttons, menus, etc) you'll have to connect those too.

If your aim is just to display a message you can follow the answer from Alex Martelli.
Else if you need some sort of execution based on close, (such as asking the user about Do you want to save the changes? kinda thing), then handling the QCloseEvent* will do the trick.
In such case what I will do is that, extend QWidget class and override its
void QWidget::closeEvent ( QCloseEvent * event ) [virtual protected]
Under the definition of closeEvent ( QCloseEvent * event ), I will have my corresponding execution.
Hope it helps..

Related

Weird artefact when resizing window [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
When I resize the window for my C++ application and make circling motions (just drag the top-left corner a bunch), it causes a strange artefact.
When I let go of my mouse:
Essentially what's happening is the application pauses whilst the window is being resized. Is there a way around this?
EDIT: Thanks for closing my question guys...
If anyone miraculously finds this question, I was able to find my own "solution". Do yourself a favour and use freeGLUT rather than SDL2, works like a charm, the set-up is much easier too.
Pretty much all window APIs(Win32, GLFW, etc) have some sort of PollEvents() function that takes all the events out of the event queue and processes them. For Win32, you have a callback function that gets called every event and you process them individually until the queue is empty. For GLFW you poll the events, then you read the state of a certain key from the updated input data (As I understand it). Regardless of the specific implementation for input, most PollEvents() functions become blocking when you either resize or move the window. What that means is that it will be constantly receiving events of type window resize or window move, even if there is no change. This causes the rendering to not update, which causes all sorts of weird stuff. The way around this is to put the PollEvents() function on a different thread than the update loop and call it repeatedly. Depending on what API you're using, there might be restrictions. For example, GLFW's PollEvents() function must be on the main thread, forcing the update loop to be on a separate thread. However, the idea is still the same across window APIs.

What causes an MFC app menu-bar to be greyed out? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm working on a legacy MFC project. The project includes an SDI application which has a menu-bar.
After launch, the menu-bar for the application is entirely greyed out:
I've read through the following questions, but they don't seem to address my situation:
MFC Menu Item remains grayed
Menu items are being enabled or disabled by default. Why?
Basically, the answers to the above question say that I need an ON_COMMAND handler, which exists for the menu functions I am interested in.
This is a very large proprietary project, so I can't simply post the code, and it could take a while to extract a minimum reproducible example. Is there any function name I can search for which might be disabling the menu-bar?
It looks to me like the entire menu bar is disabled, so I don't think my issue is related to individual ON_COMMAND handlers.
This didn't happen after some change, otherwise I would just roll back the change. I believe the application has been launching with a greyed-out menu bar since I began working on it.
The main application is a CWinApp-derived class, and the class where I added the ON_COMMAND handler is a CFrameWnd-derived class.
I'm developing in VS2019 (v142) using the Windows SDK version 10.0, and testing on Windows 10. I have a feeling (somewhat unsupported) that this particular issue is not closely related to the exact version of the compiler, or even Windows 10; my guess is that I am missing some detail of how MFC enables or disables menu-bars in general.
The "grayed out" means that the widget is disabled.
You'll need to EnableWindow on the widget.
Specifying EnableWindow(FALSE) will disable the widget (window).
The tough part is to find out where or how this function is called.
The state may be specified in a resource file.
It may also be stated in an initialization method, or a constructor.

Getting input & output from desktop with qt or c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Recently I made a program by Qt(c++) to get screen resolution and show it by moving mouse. Currently, it works well but just on the MainWindow form;
How can I make it work when I move mouse on desktop also?
I Really appreciate you if you answer.;)
If you want to get mouse input outside of the widget then you have to call QWidget::grabMouse() and later QWidget::releaseMouse() when done. Bear in mind that it may not work on some operating systems or it may stop working when your widget (MainWindow on your case) loses focus. Also it may work worse with next update of operating system. That is because operating system vendors do not like spyware that spies mouse clicks or malware that locks whole desktop.

translation of an idea in QPushButton [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to bring your attention regarding a detail which might be ridiculous for advanced people in Qt" but not for newbies as me.
I would like to connect a pushButton to a signal/slot while the user didn't press on a specified pushButton B:
What I want to do is:
do
{
QObject::connect(pushButton_image, SIGNAL(clicked()), this, SLOT(image()))
}
while (// THE USER DIDN'T PRESS THE PUSHBUTTON B ...)
As soon as the user press the PUSHBUTTON B, I want to disconnect pushButton_image with its previous signal / slot.
Thanks!
Connect it once, out of that while.
That's wrong because:
You can connect a slot to a signal multiple times. But it will be called s many times as you connected it.
You won't get out of that while loop.
A slot is connected as long as it gets disconnected. Being connected Its more like an state that an active task.
To disconnect you use
QObject::disconnect
In slot call
QObject::disconnect(pushButton_image, SIGNAL(clicked()), this, SLOT(image()))
Done

wxPanel show function does not work inside wxThreads [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
#include "MessageBoxThread.h"
MessageBoxThread::MessageBoxThread(NfcUIConfirmProcessUC* dialogUC)
{
this->dialogUC = dialogUC;
}
MessageBoxThread::~MessageBoxThread(void)
{
}
void* MessageBoxThread::Entry()
{
this->dialogUC->Show(true);
return 0;
}
To quote from the wxThread docs:
GUI calls, such as those to a wxWindow or wxBitmap are explicitly not safe at all in secondary threads and could end your application prematurely. This is due to several reasons, including the underlying native API and the fact that wxThread does not run a GUI event loop similar to other APIs as MFC. [...] the recommended way is to simply process the GUI calls in the main thread through an event that is posted by wxQueueEvent()
So basically the best way to solve this problem is rather than calling Show to create an event (for example a wxThreadEvent) post it back to the dialog and then using an event macro or bind connect it to a dialog member which shows the dialog.