I would like to play .wav samples of engine through out Qt creator. Of course the very first thought was on QSound class, but I did whatever was necessary to play it and it always shows me
QCoreApplication::postEvent: Unexpected null receiver
Which means that I entered wrong path for file, it seems simple but I have tried with absoulte paths and etc. Nothing new has happened.
Sourcecode and photos, I am trying it on windows but I would like to run it on Raspberry(fedora).
#include <QCoreApplication>
#include <QSound>
#include <iostream>
#include <QMediaPlayer>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSound let("music/letitplay.wav");
let.play();
/*QMediaPlayer * music = new QMediaPlayer();
music->setMedia(QUrl("qrc:/sounds/letitplay.wav"));
music->play();
*/
return 0;
}
Snippet from .pro
QT += core
QT -= gui
QT += multimedia
TARGET = silnik1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
RESOURCES +=
Screen of path and file directory
QSound plays sounds asynchronously; you're going to need to start your QCoreApplication first so there's an event loop running.
Related
I am following this qt tutorial.
helloworld.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = helloworld
TEMPLATE = app
SOURCES += main.cpp
main.cpp
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPushButton button ("Hello world!");
button.show();
return a.exec(); // .exec starts QApplication and related GUI, this line starts 'event loop'
}
Type the following shell commands to build the program.
qmake -project
Error:
PS E:\QT_tut\Tut_cmake_1\nSR> qmake -project
Project ERROR: Cannot run compiler 'cl'. Output:
===================
===================
Maybe you forgot to setup the environment?
PS E:\QT_tut\Tut_cmake_1\nSR>
QT: 5.12.12
VS: 2019
But, I can run this program using QT GUI.
I am stuck with the following issue:
I need to open encrypted PDF files (with known passwords) from a simple C++/Qt program with the default PDF editor on the PC. I know the password to the PDFs, this is not the issue here.
Alternatively, it would be also ok, if the PDF is rendered within my Qt window, but I think that this would be even more complicated.
I know that I am able to open standard PDFs with fairly simple commands like
QDesktopServices::openUrl(QUrl("file:///home/.../fileName.pdf"));
But I do not know any option to insert a password here.
Does anybody know a way how to do this (preferably with mainly standard C++/Qt methods)?
Thank you very much and best regards
You may decrypt the original PDF file first, for instance with the qpdf library saving the output to a temporary file, and then open this temporary file with QDesktopServices::openUrl().
To decrypt a PDF file with the qpdf command line utility, the syntax is:
qpdf --password=KNOWNPASSWORD --decrypt input.pdf output.pdf
Here is a simple example of PDF decryption using the qpdf library from a Qt program, using the pkg-config utility to configure the dependency.
test.pro
QT = core
CONFIG += c++11 console link_pkgconfig
TEMPLATE = app
SOURCES += main.cpp
PKGCONFIG += libqpdf
main.cpp
#include <QCoreApplication>
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFWriter.hh>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString inputFile = "input.pdf";
QString outputFile = "output.pdf";
QString userPassword = "USERPASS";
try
{
QPDF qpdf;
qpdf.processFile(inputFile.toLocal8Bit(), userPassword.toLocal8Bit());
QPDFWriter w(qpdf, outputFile.toLocal8Bit());
w.setPreserveEncryption(false);
w.write();
}
catch (std::exception& e)
{
qFatal("Error. %s", e.what());
}
}
I am trying to decode a .wav file using QAudioDecoder class. Even though I had included the QtMultimedia module into my .pro file by adding
QT += multimedia I am receiving an error that service for the QAudioDecoder was not found. I am not able to see where to problem lies.
I am using Qt 5.1.0 with MingGW 4.8 32 bit on Windows 7.
Error message:
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.audiodecode"
.pro file:
QT += core
QT += multimedia
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
main file:
#include <QCoreApplication>
#include <QAudioDecoder>
#include <QAudioBuffer>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString pathToFile = "C:/Users/Mateusz/Documents/Szkola/Sound Processing/Lab1/artificial/easy/506Hz.wav";
QAudioDecoder decoder;
decoder.setSourceFilename(pathToFile);
decoder.start();
while(decoder.bufferAvailable()) {
QAudioBuffer buffer = decoder.read();
qDebug() << "Buffer size: " << buffer.byteCount();
}
return a.exec();
}
The Multimedia module uses plugins that are different on each platform (or compiler).
See http://qt-project.org/wiki/Qt_Multimedia_Backends
On Windows you have DirectShow and MediaFoundation (WMF).
Only the WMF plugin implements audio decoding features.
WMF plugin is only available with MSVC compiler.
See http://qt-project.org/doc/qt-5.1/qtmultimedia/platform-notes-windows.html
I had the same problem in Qt5.5 running under Linux.
The problem disappeared after upgrade to Qt5.5.1 using their MaintenanceTool.
I also struggled with this issue and finally got it to work by using the MS visual studio compiler in QT Creator, like Fernando Pelliccioni suggested.
Steps were:
-Use the Qt MaintenanceTool to add support for msvc2013
-Install Visual Studio 2013
-In Qt Creator go to Projects->Manage Kits and add msvc2013
-Build and run. Now QAudioDecoder works.
I am trying to convert an application console mode to gui mode but the problem is the console window still appearing with main window.What i want is to hide console window as it dose in gui mode.
.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = cmd
TEMPLATE = app
CONFIG -= console
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
mainfile
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
In creator go in project under tab Run Settings uncheck Run in terminal. cmd window will not appear.
I'm trying to write a console app in Qt under Lubuntu.
But when I'm trying to run something, i.e.:
#include <QCoreApplication>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cout << " hello world";
return a.exec();
}
it fails, saying :
"Cannot change to working directory home/myusername/myproject: no such
a file or directory".
But this directory exists, there's even the build file in it, marked as executable. But when I trying to run it from the terminal, the response is: myproject-console is not a command.
What happened to "Hello, World!" app? Is there any way to solve it?
It appears that your application tries to look for a relative path home/myusername/myproject and not for the absolute path /home/myusername/myproject. Have you checked the path contained in argv?