C++:QX11EmbedContainer not working on Qt - c++

Given below is the code that I have written for opening VLC from Qt. I want to use the QX11EmbedContainer so that I can use it to "contain" VLC.
#include "mainwindow.h"
#include <QApplication>
#include <QProcess>
#include <QX11EmbedContainer>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString prog="C:/Users/Administrator/Desktop/... .exe";
QProcess *proc=new QProcess();
proc->start(prog);
return a.exec();
}
On adding the header file QX11EmbedContainer I get the following error:
C:\Users\Administrator\Documents\HA\main.cpp:4: error: C1083: Cannot open include file: 'QX11EmbedContainer': No such file or directory
Is QX11EmbedContainer an add-on? If not then where am I going wrong?

Related

QSettings iniFormat

I am trying to create an ini file from my application (Qt5.9.6):
#include <QCoreApplication>
#include <QSettings>
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
QSettings settings(QStringLiteral("C:\\test.ini"), QSettings::IniFormat);
settings.setValue(QStringLiteral("global/mykey"), 1234);
settings.sync();
app.exec();
}
The file is created, however the content is not what I expect:
[global]
mykey="\x1\x1\x1\x1"
Looks like it was a bug introduced by a colleage into our custom built Qt library.

I am unable to reference QSettings using Qt

I am running a project that uses Qt. I have installed version 5.10.1 (msvc2017_64). I receive an error that the QSettings is undefined. I cannot find the reference in the libraries installed.
#include "mainwindow.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setApplicationName("Circuit Editor");
QSettings settings;
MainWindow w;
w.setWindowTitle("Circuit Editor");
w.show();
return a.exec();
}
My two cents:
1) You forgot to include the header:
#include <QSettings>
2) You declared a QSetting object but you are not doing anything with it. Is that what you want to do?
Never use #include <QtModule/QClass> format of includes. They hide project misconfiguration. Use #include <QClass> instead.
If you're unsure of what to include, include the entire module and deal with details later: #include <QtModule>.
Thus:
#include "mainwindow.h"
#if 1
// entire module
#include <QtWidgets>
#else
// needed classes
#include <QApplication>
#include <QSettings>
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setApplicationName("Circuit Editor");
QSettings settings;
MainWindow w;
w.setWindowTitle("Circuit Editor");
w.show();
return a.exec();
}

Is QFileInfo synchronized with file?

Is QFileInfo synchronized with source file? Or it just stores information from the time when the instance was created?
In otherwords, if I create QFileInfo instance for my file. Then I change the file. And then, I create second instance of QFileInfo for this file, will they have different lastModified value?
QFileInfo is not syncronized, the information is read when the object is created.
I have used this small example to verify it.
If you run this in a terminal and then change the file you will see the date changing when you save the file.
#include <QCoreApplication>
#include <QDebug>
#include <QFileInfo>
#include <QDateTime>
#include <QThread>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
while (1)
{
QFileInfo f("./file.txt");
qDebug() << f.lastModified().toString();
QThread::sleep ( 1 );
}
return a.exec();
}

Creating a QVideoWidget in Qt5

I have the following piece of code:
#include <QtWidgets/QtWidgets>
#include <QtMultimedia/QCamera>
#include <QtMultimedia/QMediaPlayer>
int main(int argc, char * argv[])
{
QApplication testQt(argc, argv);
QMainWindow w;
QWidget videoContainer(&w);
w.setCentralWidget(&videoContainer);
QVideoWidget videoWidget(&videoContainer);
QCamera cam(&w);
cam.setViewfinder(&videoWidget);
cam.start();
w.show();
return testQt.exec();
}
in which I am trying to create a main window, create a container widget to display video, create a videowidget in that container, and then finally set the viewfinder of the camera to that videowidget. However, when I try to do this I get the error
Variable has incomplete type 'QVideoWidget'
Why am I getting this error?
You need to include the corresponding header as follows:
#include <QVideoWidget>
You may also need to add this to your project file:
QT += multimediawidgets

Can't register C++ type to QML system

I'm trying to add C++ type to QML system.
#include <QtGui/QGuiApplication>
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
#include "qtquick2applicationviewer.h"
#include <QQmlApplicationEngine>
class FooBar: public QObject {
Q_OBJECT
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine("qml/RBot/main.qml");
qmlRegisterType<FooBar>("io.secorp", 1, 0, "FooBar");
return app.exec();
}
But when I'm trying compile this(i don't import this in .qml file, only testing) I'm geting errors about debugging.
What's wrong?
Thanks.
You're mixing Qt Quick 1 and 2, which is unsupported. The QDeclarative headers are for Quick 1 and the QQml headers are for Quick 2.
Your includes should be:
#include <QtGui/QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include "qtquick2applicationviewer.h"
#include "foobar.h"
The definition of FooBar should be in its own header, and QObject should be included there for moc to work its magic.
For more details, see this already reported bug in Qt:
QTBUG-32138 - Hello World for QtQuick2 does not compile with #include when QML debugging is on