I just can't get webengine working. This is my source code:
#include <QtWidgets/QApplication>
#include <QtWebEngineWidgets/QWebEngineView>
int main(int argc, char ** argv) {
QApplication app(argc, argv);
QWebEngineView view;
view.setUrl(QUrl(QStringLiteral("http://www.qt.io")));
view.resize(1024, 750);
view.show();
return app.exec();
}
And this happens when I try to run it:
$ g++ test.cpp -I/usr/include/qt -fPIC -lQt5Core -lQt5Gui -lQt5Widgets -lQt5WebEngine -lQt5WebEngineWidgets && ./a.out
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Unrecognized OpenGL version
Unrecognized OpenGL version
No windows is shown and it just hangs there until I kill it with ^C. How can I get it to work?
Related
I created a Qt app with a GUI that can also run on the command line (by never calling QMainWindow::show()). When I try to run it on a Debian virtual machine I get the error:
$ xvfb-run ./myApp
Could not initialize GLX
Aborted
I built it on Ubuntu 16.04 with dynamic linking to the Qt libs and copied over the needed libraries. It was previously working, but started giving this error after I updated the app. How can I find out if this error is due to missing dependency or some issue with xvfb?
$ xvfb-run ./myApp
Xvfb doesn't support GLX / OpenGL. That's all. Either use a full blown Xorg server with GPU drivers or a headless EGL context.
The problem is most likely because you instantiate QApplication or QGuiApplication: not showing the window is not enough. When you run from the command line, you also need to use QCoreApplication only.
#include <QtWidgets>
#include <memory>
#ifdef Q_OS_WIN
#include <io.h>
int isatty(int fd) { return _isatty(fd); }
#else
#include <unistd.h>
#endif
using MyWindow = QWidget;
bool onCommandLine() {
return isatty(0);
}
int main(int argc, char **argv) {
std::unique_ptr<QCoreApplication> app(
onCommandLine() ? new QCoreApplication(argc, argv)
: new QApplication(argc, argv));
/* common logic goes here, e.g. argument parsing, etc. */
if (!onCommandLine()) {
MyWindow w;
w.show();
return app->exec();
} else
return 0;
}
I'd like to show and then close a dialog after 5 seconds within my main() function in a Qt Console application. Here is my code that works:
Main.cpp:
#include <QApplication>
#include "splash.h"
#include <QTimer>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// some stuff to do
Splash splash;
QTimer::singleShot(5000, &splash, SLOT(close()));
splash.exec();
// some more stuff to do
exit(0);
// return a.exec();
}
text_console.pro:
QT += widgets \
gui
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp \
splash.cpp
FORMS += \
splash.ui
HEADERS += \
splash.h
The above code complies and works, but I do not get complete intellisense for the splash object (e.g. setModal(), exec()). What am I doing wrong?
I am using Qt5 in linux.
Anyone got QT 5.6 working with OpenCV ?
Tried OpenCV latest 2.4.13 (at time of writing) and went back to OpenCV 2.4.9.
None worked - program will compile, link but crash on "During Startup program exited with code 0xc0000139". I never had any problems with QT 5.5.1 and OpenCV.
Here is stripped down code:
**mainwindow.cpp:**
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat image = cv::imread("C:/Users/foo/pics/cheetah.jpg");
cv::namedWindow("My Image");
cv::imshow("My Image", image);
cvWaitKey(0);
}
MainWindow::~MainWindow()
{
delete ui;
}
**main.cpp (used default):**
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
**mainwindow.h: (used default)**
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
**test_opencv.pro:**
INCLUDEPATH += "C:\Users\foo\Downloads\opencv\build\include"
LIBS += -LC:\Users\foo\Downloads\opencv\build\lib \
-lopencv_core249.dll \
-lopencv_highgui249.dll \
-lopencv_imgproc249.dll \
-lopencv_features2d249.dll \
-lopencv_video249.dll \
-lopencv_calib3d249.dll
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test_opencv
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
Path set:
C:\Qt\Tools\mingw492_32\bin
C:\Qt\5.6\mingw49_32\bin
C:\Users\foo\Downloads\opencv\build\bin
QT works fine with no OpenCV calls. With above code, running with QT Debug will see this:
"During Startup program exited with code 0xc0000139".
QT Error message
I have double checked my path. The OpenCV DLLs are defined in the Path. problem is not about not finding the runtime dynamically link dlls. I also checked my System32 and other directories for any old OpenCV dlls that might interfere as the path is traversed. No issues.
OpenCV was built with CMake and successfully build and installed. No issues there.
Thanks
Sean
I use UBuntu 12.04 LTS. When I run a console application using Qt Creator an output of qDebug() is not visible on a terminal (I get only an empty terminal with a cursor). How to fix that ?
Edit1 Moreover I can't stop a program using a stop button, I have to use a Force Quit option.
Edit2 Here is the code:
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug()<<"Ok";
return a.exec();
}
Edit3 Solution: Qt Creator: Run in Terminal
I'm trying to build a really simple Qt program using FFMpeg library.
Currently I just want to open and close a video file.
Here is my project file:
QT += core gui
TARGET = avtest01
TEMPLATE = app
INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib -lavformat
SOURCES += main.cpp
And my code:
#include <QDebug>
extern "C" {
#include <libavformat/avformat.h>
}
int main(int argc, char *argv[])
{
if(argc > 1)
{
AVFormatContext *format_context;
qDebug() << argv[1];
if(avformat_open_input(&format_context, argv[1], NULL, NULL) == 0)
{
qDebug() << "open";
avformat_close_input(&format_context);
}
else
qDebug() << "error opening " << argv[1];
}
return 0;
}
Unfortunately, the linker fails:
Undefined symbols for architecture x86_64:
"avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)", referenced from:
_main in main.o
"avformat_close_input(AVFormatContext**)", referenced from:
_main in main.o
I'm using Qt 5.1.0 on MacOS.
Your code worked for me after I added av_register_all(); to main.
My guess is that you have avformat compiled for 32 bit. You can confirm by running file /usr/local/lib/libavformat.dylib in terminal.
The output should look like:
/usr/local/lib/libavformat.dylib: Mach-O 64-bit dynamically linked shared library x86_64