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.
Related
Compiler complaining undefined reference to std::thread::_State::~_State() when I am trying to create RSA_PrivateKey object in Botan C++.
#include <QCoreApplication>
#include <botan/rsa.h>
#include <botan/auto_rng.h>
#include <iostream>
using std::cout;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::unique_ptr<Botan::RandomNumberGenerator> rng(new Botan::AutoSeeded_RNG);
cout << rng->name();
// this line caused the error
std::unique_ptr<Botan::RSA_PrivateKey> theKey(new Botan::RSA_PrivateKey(*rng.get(),1024));
return a.exec();
}
Error shows like this:
Error when creating RSA_PrivateKey in Botan
I'm really not sure why the compiler is complaining. I need help, thanks in advance.
I added the botan library as a static library using the ".a" file. I did it by right-clicking the project folder > add library > External Library. I tried to compile in debug.
Added botan like this
OS: Windows 7
Compiler:Qt 5.11.2 MinGW 32-bit
You should create an instance of Botan::RSA_PrivateKey :
Botan::RSA_PrivateKey rsa(*rng.get(),1024);
Main.cpp
#include <QApplication>
int main (int argc, char* argv[]) {
QApplication app(argc, argv);
return app.exec();
}
test.pro
SOURCES += \
main.cpp
greaterThan(QT_MAJOR_VERSION,4) : QT +=widgets
outputs :
I can't compile my project because of "undefined reference to", it seems that my compiler doesn't find "QApplication" but i don't know how to solve it.
I unistall and reinstall my Qt but it didn't fix it.
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
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
Now I am feeling quite stupid. I am trying to do some stuff with xlib in Qt Creator.
My code:
#include <QtCore/QCoreApplication>
#include <X11/Xlib.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Display *display = XOpenDisplay(NULL);
return 0;
}
Just one line of code and gives me:
/main.cpp:8: undefined reference to `XOpenDisplay'
It is defined in Xlib.h as
extern Display *XOpenDisplay(
_Xconst char* /* display_name */
);
I feel I am missing something very basic.
I've figured it out.
Adding -lX11 to the the Makefile solved this issue.
#КодСерфинг145 I added LIBS += -lX11 to the make file (the .pro file)
Adding Additional arguments to Build steps inside Projects did not work for me either and neither did QMAKE_CXXFLAGS += -lX11 like many suggests.