QCamera automatically reset my settings - qt

I'm trying to set a few settings in the camera example
Declaration
QCamera *camera;
QMediaRecorder* mediaRecorder;
QVideoEncoderSettings videoSettings;
Code
videoSettings.setFrameRate(10);
qDebug() << videoSettings.frameRate();
videoSettings.setQuality(QMultimedia::VeryLowQuality);
videoSettings.setResolution(200, 300);
qDebug() << videoSettings.resolution();
mediaRecorder->setVideoSettings(videoSettings);
qDebug() << mediaRecorder->videoSettings().resolution();
And it's not working, as you can see the debug log:
10
QSize(200, 300)
QSize(-1, -1) 0 // should be 200*300 an 10fps, isn't it ?
I don't understand why it's not working...

Related

QMediaPlayer::metaData always returns QVariant(Invalid)

I used Qt on MAC OS and try to retrieve the metadata of media. So i took the Qt's Media Player Example (Qt 5.8.0) and modified a little bit:
Instead of:
connect(controls, SIGNAL(play()), player, SLOT(play()));
i used:
connect(controls, &PlayerControls::play, player,
[this]{
qDebug() << player->isMetaDataAvailable();
qDebug() << player->metaData(QMediaMetaData::Size);
player->play();
qDebug() << player->isMetaDataAvailable();
qDebug() << player->metaData(QMediaMetaData::Resolution);
});
The results are:
false
QVariant(Invalid)
false
QVariant(Invalid)
1st question: why is the metadata not available even after the media started playing?
2nd question: i added some codes in the destructor:
Player::~Player()
{
qDebug() << player->isMetaDataAvailable();
qDebug() << player->metaData(QMediaMetaData::Duration);
}
Now the metadata is available, but no data is returned:
true
QVariant(Invalid)
Can anyone help me please?
Update Question 1:
Instead of
connect(controls, SIGNAL(pause()), player, SLOT(pause()));
i used:
connect(controls, &PlayerControls::pause, player,
[this]{
qDebug() << player->isMetaDataAvailable();
qDebug() << player->metaData(QMediaMetaData::Resolution);
});
And after about 3-5 seconds of playing, the metadata is already available, but it also returns nothing:
true
QVariant(Invalid)
This is not the exact answer for your question but this may help you. You can check which metadata available with this code:
QMetaDataReaderControl *c = qobject_cast<QMetaDataReaderControl*>(player_->service()->requestControl(QMetaDataReaderControl_iid));
if(c) {
connect(c, &QMetaDataReaderControl::metaDataAvailableChanged, [c](bool) {
qDebug() << c->availableMetaData();
});
}
I', not sure, but I think that qDebug cannot handle QVariant, you should use for example:
qDebug() << (player->metaData(QMediaMetaData::Title)).toString();

QtCreator semantic issue warning code will never be executed

I have following chunk of Qt code:
if(this->ueCommunicationsSocket()->bind(QHostAddress(data[0].toString()),
static_cast<quint16>(data[1].toInt())),
QAbstractSocket::ShareAddress)
{
qDebug() << Q_FUNC_INFO
<< "TCP socket bind succesfull";
}
else
{
qDebug() << Q_FUNC_INFO
<< QString::number(this->ueCommunicationsSocket()->error())
<< this->ueCommunicationsSocket()->errorString(); // here i get semantic issue
} // if
and I am getting semantic issue warning code will never be executed. I am aware this is some dumb mistake and I am ready to get downvote(s), however, I cannot find mistake! Here is also a screenshot:
if(this->ueCommunicationsSocket()->bind(QHostAddress(data[0].toString()),
static_cast<quint16>(data[1].toInt())),
QAbstractSocket::ShareAddress)
is
if ( /*something */, QAbstractSocket::ShareAddress)
since AbstractSocket::SharedAddress is 0x1, this condition with a comma operator ! is always true, i.e. the else branch will never be executed.

Qt: cannot open file for writing

I try to access a simple text file from a Qt-widget application with the QFile class for reading an writing. Reading the file line by line as a string works fine. But opening it ready to write fails. The following code checks if the file exists and tries to set the proper permissions, but in the end the file won't open.
Here is the failing piece of code:
#include "mainwindow.h"
#include <QApplication>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[]){
QApplication app(argc, argv);
MainWindow w;
w.show();
QFile file(":/test.dat");
qDebug() << "exists? " << file.exists();
qDebug() << "writable? " << file.isWritable();
qDebug() << "permissions before? " << file.permissions();
qDebug() << "permissions set? " << file.setPermissions(QFileDevice::WriteOther | QFileDevice::ReadOther);
qDebug() << "permissions after? " << file.permissions();
qDebug() << "opened? " << file.open(QIODevice::Append);
qDebug() << "errors? " << file.errorString();
qDebug() << "errnum? " << file.error();
QTextStream out(&file);
out << "something to append";
file.close();
return app.exec();
}
Qt returns this message:
exists? true
writable? false
permissions before? QFlags(0x4|0x40|0x400|0x4000)
permissions set? false
permissions after? QFlags(0x4|0x40|0x400|0x4000)
opened? false
errors? "Unknown error"
errnum? 5
QIODevice::write (QFile, ":/test.dat"): device not open
If I change the parameter in the open-function to QIODevice::ReadOnly the file is readable without problems, failing with QIODevice::WriteOnly. Why doesn't the same thing work for writing as well? Is it the permission? And why don't the permissions change after I called setPermissions? I run Qt as root on Ubuntu 14.04. And test.dat has full rights -rwxrwxrwx owned by user.
Can someone help?
Thanks!
The author is having Linux-related problem with writing to file created by console process with elevated privileges. I have fully reproduced the problem and when attempted to remove the file with:
vi \home\myuser\Documents\f.txt // create file like that from console
rm \home\myuser\Documents\f.txt // now try to remove it from console
I got "rm: remove write-protected regular file "\home\myuser\Documents\f.txt" and responded "yes" and then the code above shows after creating new file in the context of the program's process:
opened? true
exists? true
writable? true
permissions before? QFlags(0x4|0x20|0x40|0x200|0x400|0x2000|0x4000)
permissions set? true
permissions after? QFlags(0x4|0x20|0x40|0x200|0x400|0x2000|0x4000)
errors? "Unknown error"
errnum? 0
I run Qt Creator as root on Ubuntu 14.04.
It does not ensure the privileges of the program you run from it, I guess. UPDATE: make sure you run the program with appropriate permissions e.g. Root in this case.

QDesktopWidget::screenGeometry returning incorrect value

I have Qt 5.3 running on top of DirectFB 1.7.4 (along with a tiny patch to qdirectfbintegration because platformNativeInterface was not implemented).
I come up in 3840x2160 resolution, then change to 1920x1080 resolution using the code below. The resolution changes and I can confirm looking at fbset output. The problem I am seeing is that after changing the resolution to 1920x1080 Qt still reports it as 3840x2160.
Does anyone know how to force Qt to recheck/update the resolution it is reporting? Or what might be missing from the directfb plugin to notify Qt that something has changed under the hood?
Thanks.
IDirectFB * dfb = (IDirectFB*)m_app->platformNativeInterface();
if(dfb){
std::cerr << "######## New resolution is " << width << "x" << height << std::endl;
IDirectFBDisplayLayer *layer;
DFBDisplayLayerConfig config;
std::cerr << "######## Getting primary IDirectFBDisplayLayer" << std::endl;
/* Get an interface to the primary layer. */
dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer);
if(layer){
DFBResult dres;
std::cerr << "######## Got the primary display layer, setting admin" << std::endl;
// This level allows window stack mode switches
dres = layer->SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE);
if(dres != DFB_OK){
std::cerr << "######## Error: " << DirectFBErrorString(dres) << std::endl;
}
std::cerr << "######## Getting layer configuration" << std::endl;
// Get layer configuration
dres = layer->GetConfiguration(layer, &config);
if(dres != DFB_OK){
std::cerr << "######## Error: " << DirectFBErrorString(dres) << std::endl;
}
// Set the new resolution
std::cerr << "######## Setting layer resolution" << std::endl;
config.width = width;
config.height = height;
dres = layer->SetConfiguration(layer, &config);
if(dres != DFB_OK){
std::cerr << "######## Error: " << DirectFBErrorString(dres) << std::endl;
}
}
// Print out resolution from Qt
QRect res = QApplication::desktop()->screenGeometry();
std::cerr << "######## QApplication resolution is now " << res.width() << "x" << res.height() << std::endl;
The output I see from the console is:
######## New resolution is 1920x1080
######## Getting primary IDirectFBDisplayLayer
######## Got the primary display layer, setting admin
######## Getting layer configuration
######## Setting layer resolution
(*) FBDev/Mode: Setting 1920x1080 ARGB
(*) FBDev/Mode: Switched to 1920x1080 (virtual 1920x2160) at 32 bit (ARGB), pitch 7680
######## QApplication resolution is now 3840x2160
root#output:~# fbset
mode "1920x1080-24"
# D: 74.250 MHz, H: 27.000 kHz, V: 24.000 Hz
geometry 1920 1080 1920 2160 32
timings 13468 148 638 36 4 44 5
accel false
rgba 8/16,8/8,8/0,8/24
endmode
The directfb qpa plugin is lacking several features. I'm working on some updates to the plugin, I'll post a link here when I submit them.
For a temporary workaround calling:
WindowSystemInterface::handleScreenGeometryChange(m_app->screens().first(), QRect(0,0,width,height));
is working to update the resolution in Qt.

Qt: QUrl::fromUserInput intepretes FTP Url wrong

I have some issue in passing a FTP string into QUrl:
std::cout << QUrl::fromUserInput("ftp://user#host.com:password#ftphost:21/path/file.ext").toString().toStdString().c_str() << std::endl;
Is always resulting in
http://ftp//user#host.com:password#ftphost:21/path/file.ext
which is obviously wrong. What's the problem with the above FTP Url? Or is that a known issue within Qt4?
I am working on Linux, using Qt 4.8.1.
Even following code
if(QUrl("ftp://user#host.com:password#ftphost:21/path/file.ext").isValid())
std::cout << "is valid" << std::endl;
else
std::cout << "is not valid" << std::endl;
Is resulting in "is not valid"
Thanks in advance
You need manually replace # in username with %40. That's what QUrl does internally if QUrl::setUserName() is called with user#domain.tld.

Resources