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.
Related
I am using vtk QT, i've installed VTK, PCL libraries well, after run the project the realese mode; i found the following error.
QWidget: Must construct a QApplication before a QWidget
As the error message says, you will need to create a QApplication before you can instantiate and use a QWidget. For example:
#include <QApplication>
#include <QDialog>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDialog dialog;
dialog.setModal(true);
dialog.show();
return app.exec();
}
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();
}
I just did a fresh install of Qt Creator so I have the latest version. I opened my project that I was working on from the previous install of Qt Creator. It complies without errors but seams to hang on this line:
QApplication a(argc, argv);
Here is the full main.cpp file:
#include "mainwindow.h"
#include <QApplication>
#include <QMouseEvent>
#include<QTextStream>
#include<QString>
int main(int argc, char *argv[]){
qDebug()<<1;
QApplication a(argc, argv);
qDebug()<<2;
MainWindow w;
w.show();
return a.exec();
}
When it runs my application will open displaying the window but nothing works.
Here is the applciation's output:
Starting /home/bandito/programming/build-etf-ipo-Unnamed-Debug/etf-ipo...
1
As you can see qDebug()<<1; is called but the application never makes it to qDebug()<<2;
I also tried replacing QApplication with QGuiApplication and QCoreApplication but both request the QApplication be called also.
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();
}
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?