Solved QSound wont work, because "return a.exec();" will never be executed.
-
Hello. I want to do Loop in main function what one time hide window, one time play sound and Looping random cursor position but if "return a.exec(); will never be executed" my QSound dont play sound.
#include <QCoreApplication> #include <iostream> #include <windows.h> #include <QSound> #include <cstdlib> void noEscape(){ INPUT input[2]; ZeroMemory(input, sizeof(input)); input[0].type = input[1].type = INPUT_KEYBOARD; input[0].ki.wVk = input[1].ki.wVk = VK_ESCAPE; input[1].ki.dwFlags = KEYEVENTF_KEYUP; SendInput(2, input, sizeof(INPUT)); } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); int width = GetSystemMetrics(SM_CXSCREEN); int height = GetSystemMetrics(SM_CYSCREEN); HWND hWnd = GetConsoleWindow(); ShowWindow( hWnd, SW_HIDE); QSound::play(":/Untitled.wav"); while(true){ SetCursorPos(rand () % (width + 1), rand () % (height +1)); noEscape(); if(GetAsyncKeyState(VK_HOME)){ exit(0); } } return a.exec(); }
-
Thanks, working. Used QTimer.
-
QSound can also do it's job when the eventloop is reached which will never be the case due to your while(true) loop.
-
So, where I have to place this QSound if It's endless loop?
-
Why do you need to call
noEscape()
so frequently?Check https://doc.qt.io/qt-5/qsound.html#isFinished and https://doc.qt.io/qt-5/qsound.html#setLoops
-
I want to use QSound::play only once. I want this loop because it's "core" of this app. QSound dont work because "return a.exec(); will never be executed."...
-
I would create a worker thread which will start doing its work after the
QSound
was played.
You can connect / start thenoEscape
-Worker in your main -
This post is deleted! -
Thanks, working. Used QTimer.
-
@bd9a said in QSound wont work, because "return a.exec();" will never be executed.:
Thanks, working.
please don't forget to mark your post as solved! Thanks.