Internal exaption on play sound in QMediaPlayer - windows

When I try to execute "play" with loop on file that not exist, I got exaption "stack_overflow".
I use Qt 5.15.2 and windows 7
playlist->addMedia(QUrl::fromLocalFile("not_exist"));
playlist->setPlaybackMode(QMediaPlaylist::Loop);
QMediaPlayer *music = new QMediaPlayer();
music->setPlaylist(playlist);
music->play();
Can I catch this exception or maybe I can use another way to run sound in the loop to exclude this problem?

You have to use the error signal of QMediaPlayer:
connect(music, QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error),
[music](QMediaPlayer::Error error){
qDebug() << error << music->errorString();
});
Output:
QMediaPlayer::ResourceError "Could not open resource for reading."

Related

Getting net.schmizz.sshj.xfer.scp.SCPException: EOF while expecting response to protocol message. while uploading file from linux to windows

I am using net.schmizz.sshj.xfer.scp.SCPFileTransfer class to upload file from local to remote server. It is failing with following error:
net.schmizz.sshj.xfer.scp.SCPException: EOF while expecting response
to protocol message. Additional info: bash: -c: line 0: unexpected EOF while looking for matching
bash: -c: line 1: syntax error: unexpected end of file
This issue I am facing only when remote machine is Windows. For Linux machine it is successfully uploading.
I have tried following steps in my code.
1. Download a file from remote machine to local
2. Upload same file again back to remote.
It is failing in step 2.
#Override
public boolean upload(String localLocation, String remoteLocation) throws SSHClientException {
this.ensureConnected();
SCPFileTransfer scp = this.sshj.newSCPFileTransfer();
try {
scp.upload(localLocation, remoteLocation);
} catch (IOException e) {
log.error("Failed to copy file {} from local path at {} to remote location {} at {}" + remoteLocation,
hostname, localLocation, e);
return false;
}
return true;
}
Any leads will be really helpful.
Thanks.
I got the solution.
The remote file path that I have used looks like :
'/cygdrive/c/Program Files/XXX/'
The issue is "'" in the path. Removal of "'" from the path results successful upload of the file.
Thanks to all who gave me leads.
Thanks,
Shruti

Can't remove file previously created by the application in Qt 4.8 on Win 7

I've copied a .bat-file from Qt-ressources to a file system and executed it.
After that I wanted to delete the file, but it fails in Qt. If fails also when I restart the application. However, the file can be removed in the file-explorer.
I tried QFile::remove as well as QDir::remove. Static as well as not-static versions - no effect.
I tried to call using native file-separator - didn't help either.
What is wrong with this code?
if ( QFileInfo( dataRootPath+"/backupdb.bat" ).exists() )
{
//debugger stepps in
QFile f( QFileInfo( dataRootPath+"/backupdb.bat" ).canonicalFilePath());
f.remove( );
}
I had the same problem copying file from resources to file system and trying to remove it after that. QFile::errorString() returns "Access denied". So it seems that resource file has some nasty permissions that are copied by QFile::copy. May be it's possible to change permissions but I used my own 2 functions to copy file:
bool copyTextFile(QString srcPath, QString dstPath)
{
QFile file(srcPath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return false;
return writeTextFile(QString::fromUtf8(file.readAll()), dstPath);
}
bool writeTextFile(QString data, QString dstPath)
{
QFile file(dstPath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return false;
QTextStream stream(&file);
stream << data;
return true;
}
I change its permissions before remove it.
QFile::copy(":/res/1.txt", "D:\\1.txt");
QFile file("D:\\1.txt");
file.setPermissions(file.permissions() |
QFileDevice::WriteOwner |
QFileDevice::WriteUser |
QFileDevice::WriteGroup |
QFileDevice::WriteOther);
file.remove();
I encountered the same error, but in my case the posted solutions did not work. However, it turned out that I had created a std::ofstream object in my code, that was unclosed. Thus, this was keeping the source file open which prevented the copying on Windows.

Can QMediaPlayer play .wav audio files?

I wrote a test application to play '.wav' audio files using qt(latest version) on mac (OSX Yosemite Version 10.10.5). Here is the code from cpp file.
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
m_player = new QMediaPlayer(this);
connect(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(onMediaStatusChanged()));
connect(m_player, SIGNAL(positionChanged(qint64)), this, SLOT(onProgressed(qint64)));
m_player->setMedia(QMediaContent(QUrl("/Users/testUser/Library/Metal.wav")));
m_player->play();
}
Widget::~Widget()
{
}
void Widget::onProgressed(qint64 pos)
{
qDebug()<<"Position is:"<<pos;
}
void Widget::onMediaStatusChanged()
{
qDebug()<<"Media Status Changed:" << m_player->mediaStatus() << " " << m_player->error();
}
and here is the output I am getting
Media Status Changed: QMediaPlayer::LoadingMedia QMediaPlayer::NoError
[11:16:13.300] FigByteFlumeCustomURLOpen signalled err=-12936 (kFigByteFlumeError_BadState) (no provider) at /SourceCache/CoreMedia/CoreMedia-1562.240/Prototypes/FigHTTP/FigByteFlumeCustomURL.c line 1486
Media Status Changed: QMediaPlayer::InvalidMedia QMediaPlayer::FormatError
I don't understand why I am getting Format error and however, the same code (except the path of the track) in windows is working fine.
Is there a fix for QMediaPlayer on Mac or Should I be using other APIs to play .wav files?
Any help would be appreciated! Thanks.
I suspect the reason of the failure (or at least one of them) is that you are passing a file path to QUrl instead of a URL. So either you set "file:///Users/testUser/Library/Metal.wav" or you use QUrl::fromLocalFile("/Users/testUser/Library/Metal.wav").

ExecJS: keeping the context between two calls

I'm currently trying to use ExecJS to run Handlebars for one of the product I work on (note: I know the handlebars.rb gem which is really cool and I used it for some times but there is issues to get it installed on Windows, so I try another homemade solution).
One of the problem I'm having is that the Javascript context is not kept between each "call" to ExecJS.
Here the code where I instantiate the #js attribute:
class Context
attr_reader :js, :partials, :helpers
def initialize
src = File.open(::Handlebars::Source.bundled_path, 'r').read
#js = ExecJS.compile(src)
end
end
And here's a test showing the issue:
let(:ctx) { Hiptest::Handlebars::Context.new }
it "does not keep context properly (or I'm using the tool wrong" do
ctx.js.eval('my_variable = 42')
expect(ctx.js.eval('my_variable')).to eq(42)
end
And now when I run it:
rspec spec/handlebars_spec.rb:10 1 ↵
I, [2015-02-21T16:57:30.485774 #35939] INFO -- : Not reporting to Code Climate because ENV['CODECLIMATE_REPO_TOKEN'] is not set.
Run options: include {:locations=>{"./spec/handlebars_spec.rb"=>[10]}}
F
Failures:
1) Hiptest::Handlebars Context does not keep context properly (or I'm using the tool wrong
Failure/Error: expect(ctx.js.eval('my_variable')).to eq(42)
ExecJS::ProgramError:
ReferenceError: Can't find variable: my_variable
Note: I got the same issue with "exec" instead of "eval".
That is a silly example. What I really want to do it to run "Handlebars.registerPartial" and later on "Handlebars.compile". But when trying to use the partials in the template it fails because the one registered previously is lost.
Note that I've found a workaround but I find it pretty ugly :/
def register_partial(name, content)
#partials[name] = content
end
def call(*args)
#context.js.call([
"(function (partials, helpers, tmpl, args) {",
" Object.keys(partials).forEach(function (key) {",
" Handlebars.registerPartial(key, partials[key]);",
" })",
" return Handlebars.compile(tmpl).apply(null, args);",
"})"].join("\n"), #partials, #template, args)
end
Any idea on how to fix the issue ?
Only the context you create when you call ExecJS.compile is preserved between evals. Anything you want preserved needs to be part of the initial compile.

CUDAPP 1.1 cudppSort configuration error (Invalid configuration argument)

I am trying to call cudppSort to sort a set of keys/values. I'm using the following code to set up the sort algorithm:
CUDPPConfiguration config;
config.op = CUDPP_ADD;
config.datatype = CUDPP_UINT;
config.algorithm = CUDPP_SORT_RADIX;
config.options = CUDPP_OPTION_KEY_VALUE_PAIRS | CUDPP_OPTION_FORWARD | CUDPP_OPTION_EXCLUSIVE;
CUDPPHandle planHandle;
CUDPPResult result = cudppPlan(&planHandle, config, number_points, 1, 0);
if (CUDPP_SUCCESS != result) {
printf("ERROR creating CUDPPPlan\n");
exit(-1);
}
The program exits, however on the line:
CUDPPResult result = cudppPlan(&planHandle, config, number_points, 1, 0);
and prints to stdout:
Cuda error: allocScanStorage in file 'c:/the/path/to/release1.1/cudpp/src/app/scan_app.cu' in line 279 : invalid configuration argument.
I looked at the line in scan_app.cu. It is,
CUT_CHECK_ERROR("allocScanStorage");
So apparently my configuration has an error that is causing the allocScanStorage to bomb out. There are only two calls to CUDA_SAFE_CALL in the function and I don't see a reason why either has anything to do with the configuration.
What is wrong with my configuration?
So that this doesn't sit around as an unanswered question (I'm not sure if this is the right SO etiquette but it seems like an answered question shouldn't sit around unanswered...), I'm copying the comment I made above here as an answer since it was the solution:
I figured this out (I'm still learning CUDA at the moment.) Because the error checking is asynchronous errors can show up in strange places if you don't check for them from time to time. My code had caused an error before I called cudppPlan but because I didn't check for errors the cudppPlan reported the error as if it was in cudppPlan.

Resources