QtCreator semantic issue warning code will never be executed - qt

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.

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();

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.

How to check why QOpenGLVertexArrayObject::create fails

I have got the following code for creating a VAO :
// VAO
mVAO = new QOpenGLVertexArrayObject();
if (!mVAO->create()) {
qDebug() << "ERROR: VAO creation failed";
}
mVAO->bind();
// VBO
mVBO = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
if (!mVBO->create()) {
qDebug() << "ERROR: VBO creation failed";
}
mVBO->setUsagePattern( QOpenGLBuffer::StreamDraw );
mVBO->bind();
mVBO->allocate( mVertices.constData(), mVertices.count() * 3 * sizeof( float ) );
mProgram.enableAttributeArray(mVertexAttrLoc);
mProgram.setAttributeBuffer(mVertexAttrLoc, GL_FLOAT, 0, 3 ); // uses the currently bound VBO
// This is imp, we do not want any more state info recorded
mVAO->release();
mVAO->create() fails in the above code. But the VBO creation does not fail. I am not sure how to find out a more detailed reason as to why the VAO creation fails.
One other thing is I am using Qt 5.2 and a laptop with a dual video card and the nvidia optimus thingy. But I can see the program is executed by the nvidia card and not the onboard intel card. So it probably is not a hardware capabilities issue.
The OpenGL version reported by
qDebug() << "OpenGL version:" << QGLFormat::openGLVersionFlags();
is OpenGL version: QFlags(0x800) which is QGLFormat::OpenGL_ES_Version_2_0
Maybe the ES version is whats standard in laptops ?
I used this as a reference to write the code : http://www.kdab.com/opengl-in-qt-5-1-part-2/

QProcess and shell : Destroyed while process is still running

I want to launch a shell script with Qt.
QProcess process;
process.start(commandLine, QStringList() << confFile);
process.waitForFinished();
if(process.exitCode()!=0)
{
qDebug () << " Error " << process.exitCode() << process.readAllStrandardError();
}
else
{
qDebug () << " Ok " << process.readAllStrandardOutput() << process.readAllStrandardError();
}
The result is :
Ok : Result.... " "" QProcess : Destroyed while process is still
running.
This message does not appear every time.
What is the problem?
process.waitForFinished(); is hitting the default 30 seconds timeout. Use process.waitForFinished(-1); instead. This will make sure you wait for however long it takes for the process to finish, without any timeout.
Note you create QProcess into the local scope. This means that the object will be deleted when you exit the scope. In the destructor QProcess process terminates. The message "Destroyed" while "the process is still running" when the process terminates in the destructor.
For solving this problem, you should call QProcess destructor when process is already terminated.
If will be QProcess::waitForFinished(-1) into your example, it will occur, but this will block you application.

How use Procedure.Exec with C++Builder XE

I have a piece of code as show belowe, wich run well with C++Builder-6.
Now I have moved tha program to C++Builder-XE and the call to "RiconfiguraNodo << nomeNodo ...." give me the ambguity error report belowe.
I tried several way to rewrite the call to the ole proceudre "RiconfiguraNodo", but I didn't find a working solution.
How can I rewrite this snippet of code in way suitable for C++BuilderXE
Error reported:
[BCC32 Error] UnitMain.cpp(262): E2015 Ambiguity between 'operator
System::AutoCmd::<<(const System::Currency) at c:\program files
(x86)\embarcadero\rad studio\8.0\include\windows\rtl\sysvari.h:3561'
and 'operator System::AutoCmd::<<(const System::TDateTime)
at c:\program files (x86)\embarcadero\rad
studio\8.0\include\windows\rtl\sysvari.h:3562'
Full parser context
UnitMain.cpp(245): parsing: void _fastcall TFormMain::RiconfiguraNodo(System::UnicodeString,System::UnicodeString,System::UnicodeString,System::UnicodeString)
Sample code:
Procedure RiconfiguraNodo( L"RiconfiguraNodo" );
if (VarServerPmvManager.IsEmpty() || VarServerPmvManager.IsNull())
{
VarServerPmvManager = VarServerPmvManager.CreateObject(ProgId_ServerPmvmanager);
}
try
{
VarServerPmvManager.Exec( RiconfiguraNodo << nomeNodo << ipAddress << tipoPmv << cmdType );
}
catch (Exception & ex)
{
Mylog(Fun + Sysutils::Format("ERROR=[%s] ", ARRAYOFCONST((ex.Message))));
}
I found the solution.
The procedure exec simply require Variant instead of plain string
Variant vNomeNodo, vIpAddress, vTipoPmv, vCmdType;
vNomeNodo = nomeNodo;
vIpAddress = ipAddress;
vTipoPmv = tipoPmv;
vCmdType = cmdType;
VarServerPmvManager.Exec( RiconfiguraNodo << vNomeNodo << vIpAddress << vTipoPmv << vCmdType );

Resources