In QT creator, I am developing a program in QT and need to include the following files:
QPtrList.h
QPtrQueue.h
QString.h
However these files do not seem to be present and I am getting this error:
Expected temeplate-name before '<' token
Is there anyway to add these files to my installation of QT?
Use QT4.8 or QT5 (5 is better)
QPtrList.h and QPtrQueue.h are not supported by QT4.8 and QT5.
Use #include <QList> instead of QPtrList.h
Use #include <QQueue> instead of QPtrQueue.h
Example "console" in QT5:
#include <QList>
#include <QQueue>
#include <QString>
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}
Pro file:
QT += core
QT -= gui
TARGET = untitled8
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
Related
Hello I want to create a Qt5 project using Qt-creator and want to use mpfr/gmp so I need how to configure the project.
because if i compile I get these errors:
#include "mainwindow.h"
#include <QApplication>
#include <stdio.h>
#include <gmp.h>
#include <mpfr.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
mpfr_t x, y, z, t;
mpfr_inits2 (256, x, y, z, t, (mpfr_ptr) 0);
return a.exec();
}
The output:
error: undefined reference to `mpfr_inits2'
But on codeblocks I add the include path and library path and add the flags -lgmp -lmpfr to the compiler and works fine.
In QtCreator, open the .pro file of your project and append the following line:
unix: LIBS += -lmpfr -lgmp
Alternatively, you can also use the UI to do this: In the "Projects" list, right-click on your project, select "Add library" > "System Library". In the "Library file" field add e.g. /usr/lib/mpfr.so. QtCreator will then turn this into -lmpfr, as shown in the "Summary" view. Repeat these steps to add /usr/lib/libgmp.so as well.
I am using Qt5 and I found this example code , but I need to show video in some of available Qt visual objects, in which objects I can use this video overview code with VideoWidget? I am Qt beginner, and I am trying to understand how Qt works.
Thanks!
In C++, a QVideoWidget inherits from QWidget, you can put in a window or in another widget.
There's an example "videowidget" project in the Examples directory of the Qt sources.
A minimal exemple:
main.cpp
#include <QApplication>
#include <QMainWindow>
#include <QVideoWidget>
#include <QMediaPlayer>
#include <QMediaPlaylist>
int main(int argc, char * argv[])
{
QApplication testApp(argc, argv);
QMainWindow w;
QVideoWidget videoWidget(&w);
w.setCentralWidget(&videoWidget);
QMediaPlayer *player = new QMediaPlayer(&w);
player->setMedia( QUrl::fromLocalFile("E:\\big_buck_bunny.mp4") );
player->setVideoOutput(&videoWidget);
w.show();
player->play();
return testApp.exec();
}
test_video.pro:
QT += core gui widgets multimedia multimediawidgets
TARGET = test_video
TEMPLATE = app
SOURCES += main.cpp
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?
I'm creating a very simple C++ QT console application from an example given here on stack overflow.
How to use QFileSystemWatcher to monitor a folder for change
The code is exactly as the code in that application and I'm developing with Qt's UI, Qt Creator with MinGW 32bit. I selected the console application from the projects I could choose as I have no need for a graphical user interface. Once the application has finished loading, the application shows the error message "WARNING: QApplication was not created in the main() thread" then does nothing.
I have tried debugging the application but get no breakpoints hit, I don't think debugging is working in the editor.
I had a quick go and changed the QApplication to a QCoreApplication seen as I am developing a console application but get the exact same error message.
filesystemreceiver.h
#ifndef FILESYSTEMRECEIVER_H
#define FILESYSTEMRECEIVER_H
#include <iostream>
using namespace std;
#include <QtCore/QApplication>
#include <QtCore/QFileSystemWatcher>
#include <QtCore/QDebug>
#include <QtWidgets/QWidget>
#include <QtWidgets/QMessageBox>
class MyClass : public QWidget
{
Q_OBJECT
public:
MyClass(QWidget* parent=0)
:QWidget(parent){}
~MyClass() {}
public slots:
void showModified(const QString& str)
{
Q_UNUSED(str)
cout << "A message has been received!" << endl;
//QMessageBox::information(this,"Directory Modified", "Your Directory is modified");
}
};
#endif // FILESYSTEMRECEIVER_H
main.cpp
#include <iostream>
using namespace std;
#include <QtCore/QApplication>
#include <QtCore/QFileSystemWatcher>
#include <QtCore/QDebug>
#include <QtWidgets/QWidget>
#include <QtWidgets/QMessageBox>
#include "fileSystemReceiver.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QFileSystemWatcher watcher;
watcher.addPath("C:/QtTest");
QStringList directoryList = watcher.directories();
Q_FOREACH(QString directory, directoryList)
qDebug() << "Directory name" << directory <<"\n";
MyClass* mc = new MyClass;
QObject::connect(&watcher, SIGNAL(directoryChanged(QString)), mc, SLOT(showModified(QString)));
return app.exec();
}
My pro file looks like this:
QT += core
QT += widgets
QT -= gui
TARGET = fsw
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
HEADERS += fileSystemReceiver.h
SOURCES += \
main.cpp
You have had several issues ongoing in your project:
QCoreApplication in a program that is supposed to show a QWidget
Calling the main.cpp source file main.moc. That indicates that you do not quite understand how moc works and what it is about.
cout in a Qt program as opposed to QTextStream or qDebug().
Q_FOREACH in a source code not reused by other application, and hence no collision could normally occur. You should use "foreach" simply.
You are not using const reference for the string while iterating with the foreach even though you seem to be only reading it, not modifying.
You have hard coded path here instead of a const string in a well separated place: watcher.addPath("C:/QtTest");
You are adding widgets to the CONFIG variable, but you remove gui.
You are adding `core to the CONFIG variable when that is in there by default.
You include #include <QtWidgets/QFoo> instead of #include <QFoo> to keep the option of building with Qt 4, and in general with clearly buildsystem include paths.
You are adding CONFIG += console for a non-console based application.
You are adding CONFIG -= app_bundle for a non-console based application.
You are using back-slash for the SOURCES variable, but not for the HEADERS. This is inconsitent.
You create a MyClass instance on the heap as opposed to the stack to make it simpler for you as it is already properly guarded by the event loop to remain valid for the intended scope.
On top of all that, your issue seems to be with qDebug() based on the comment discussion. You should follow the document below how to set up QtCreator for debugging properly.
Setting Up Debugger
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