QSystemTrayIcon keeps creating new icons - c++

I've created a notification system that makes use of QSystemTrayIcon to alert the user. My issue is that each time a user receives a notification it creates a new icon so the system tray ends up full of these icons.
I develop the program on a Linux machine and the issue doesn't occur here. However, I build the program on Windows 7 which is where the program is actually used and where the issue arises. This makes testing tricky for me as I have to go through quite a lengthy process to even run the program on Windows. So I'm kind of hoping someone can spot the issue and tell me exactly what is wrong but I appreciate any input so please if you have any idea do tell.
My code:
QSystemTrayIcon* notiTray = new QSystemTrayIcon(this);
notiTray->setIcon(QIcon(":/icon.png"));
notiTray->setVisible(true);
notiTray->showMessage("Notifications, "You have new notifications", QSystemTrayIcon::Information, 60000);
notiTray->show();
QApplication::alert(this, 1000);
This code is inside an if statement inside a function that gets called every 5 seconds to check for new notifications.
At a guess I'd say it might be because a new SystemTrayIcon is made everytime a notification arises but I'm not 100% and I was hoping anyone might be able to confirm this to save me from going through an awful process of testing it on Windows.
Thanks for any help!

Related

Listening to and calling wxPython event from another process

I'm currently trying to develop a proof of concept for a possible idea but am unsure if this is even possible.
We have application A, written in wxPython, which will not receive any code updates. It's too late in its life and will impact too many people. In a specific case which we wish to automatic - a GUI window pops up asking user to select an option from the list.
We want to develop script or "application B" which listens for this GUI to pop up and automatically makes the choice. It can be a script that runs in the background at all times.
Now.. from my understanding I don't think it's possible without some interprocess communication going on. Since we cannot change anything in application A the problem seems unsolvable. Any ideas? Am I missing something about how I could use wxPython?

Debugging a Win32 application c++

My application started life as a c++ Console application in VS2019. Code was provided as part of an SDK. Worked perfect. Great response from the manufacturer USB device. Later, I wanted to graduate is to a GUI application, much as I've been doing in VB and c#. Lo and behold, I managed to reconstruct the application in both Qt and Win32 but I'm running into a situation where the application becomes unresponsive and I have no way to tell what's going on.
In the Console application, I have to execute this code to interface with the device AFTER sending a "TakeMeasurement" command :
if (SDK_SUCCESSFUL(sdkError)) {
printf("\nWaiting for measurement to complete...\n");
while (!isMeasureWait) {
if (isDisConnect) break;
this_thread::sleep_for(chrono::milliseconds(1000));
}
}
This code works like a charm! Ater one or two iteration, the device has completed the measurement and I can get to the data easily.
On the Win32 side, I use the exact same code. Only, once control enters the loop, it never returns.
Any idea how I could diagnose the error? I have the impression that the "timing" is critical, between the exact moment where the Measurement command is initiated to the exact moment the instrument signals that it's done, and the data ready to be picked up.
My naive hypothesis is that, in debug mode on both 'platforms', I must be getting some timing differences? Sadly, I can't get more information from the manufacturer in this regard but I suspect I have a small window of time within which the instrument's response can be acted on? And I begin to suspect that, on Win32, that "time" is too long? Compared to on the Console side?
I was thinking of, perhaps, "measuring" that time, in milliseconds? First, on the Console side, to see what kind of delay "works", and then, to see how the delay compares with the Win32 side.
I may be wasting my time and I sure don't mean to waste yours.
How would I go about getting an idea of time elapsed in a c++ application? I'll take a look around VS2019, they have all kinds of "performance" things that popup at run time?
Any help is appreciated.
I am not sure I completely understand what is going on.
Execution of the thread wait loop was not not the culprit.
I'm not 100% sure but what happens is that, in my 'Export data to CSV TEXT file', if I tried to execute the call to :
SetWindowText(hEditMeasure, wMeasurements);
The application always hung. I placed breakpoints right before the call in the code, to trace execution, and it did not strike me at first but, in VS toolbar, there was a "thread" comboBox? With the value showing = DEVICE.DLL? and to its right, the name of my Export function as the Stackframe. In searching for additional information on the setWindowText function, I came accross the reference to use VM_SETTEXT to send to "different application"? Could it be unknowingly I was sending a message to "another thread", the DLL thread? And that's why it hung? I did not know enough to tell. So I started to move the setWindowText line around, ultimately inside the code that is called by the "Measure" button, and it worked!
I'm not out of the woods yet but I feel I'm making progress. Thank you all for your help and patience.

QT5.3.2 + VTK6.1 C++ program quits randomly after long time running

I have a C++ program written together with QT5.3.2 + VTK 6.1. The program compiles fine and can run after deployment. Each function button also works fine.
The problem happens when I run this program for weeks (its a motion control software, so it needs to be on for a long time). Randomly(probably not random at all...) it quits/crashes without a frozen window. In another word, the program window just closes and no error message window appears.
I met the memory leak issue before, the program window first froze and the cursor kept busy status and unresponsive. But this time it just closes itself without any error message or unresponsiveness.. Could this also be a memory leak issue?
So I really appreciate it if someone can give me some hint or direction to troubleshoot this issue by their rich experience in programming.
Since there is a lot of code and I do not know where the problem comes from. I will not post code for now but I am happy to include some key aspects:
It uses ADS communication to communicate with hardware drives.
Callback function to fetch the monitoring data and display in QT interface, meaning a lot of actions like LineEdit->SetText() are used repeatedly. SetText() is called with a global qapplication pointer *tp->SetText().
VTK just displays the 3D data. And I separately tested there is no memory leak.
I am happy to share more information if needed.
Memory leak test.

Continuously (asynchronously) poll and update label in C++ GUI application

I have an application that opens another process and modifies its memory. What I'd like to have as a part of the GUI is a label that updates (perhaps every second or so) to let the user know if they're attached to the other process.
When the application is found running, I'm creating a handle to it, obtaining the base address of it, and then the rest of the work is done through button clicks and hotkeys. Anyway, for each time the application is found running, I want it to do all the things I have it do to obtain the handle, etc., etc.
This way, the other application can be closed and reopened without my app also needing to be closed/reopened accordingly.
Thus far, my research has led me to CreateThread() and std::async (as well as std::launch::async and std::launch::deferred). The issue I'm having is I can't seem to find examples of infinitely-running asynchronous code (in its own thread, perhaps). I'm having a difficult time wrapping my head around how to make this happen, as everything I've tried still keeps execution from continuing as if I'd just written a while loop in main() or something.
Anything exemplifying the type of functionality I'm looking to achieve would be immensely appreciated! Thanks for your time and help, everyone.

Background process without a window

I need to prepare a program which runs in the background without a window or anything on the taskbar. You may compare this to the idea of a program which runs in the background and sends a signal every once in a while to keep the computer from sleeping.
So here are the two ideas that I have on my mind
1) Creating a windows Service
2) Spawning a thread and exiting main
Please let me know how viable these are, particularly the second one, and what other possibilities do we have at our disposal.
Thanks in advance!!
Just link your application for windows subsystem, not console
If you're looking to run a background process then go with the service approach. You'll be able to configure it to run even when nobody is logged in and it won't be intrusive to the user.