Specific websites throwing an exception in QWebView - c++

While running my code I am getting a Write Access Violation Exception when it tries to use QWebView:
Minimal compilable code for reproducing the error
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWebKitWidgets/QWebView>
#include <QUrl>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWebView *wv = new QWebView(this);
wv->load(QUrl("http://steamcommunity.com/"));
setCentralWidget(wv);
}
MainWindow::~MainWindow()
{
delete ui;
}
The pro file also includes webkitwidgets and network:
QT += core gui webkitwidgets network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MyApp
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
Error Hints
The error I get looks like this:
ASSERTION FAILED: leftSide->category() != CalcOther && rightSide->category() != CalcOther
css\CSSCalculationValue.cpp(290) : WebCore::CSSCalcBinaryOperation::create
1 0354A5B7
2 02E58E41
3 02E59520
...
I can't provide a stack trace because the error is in one of the Qt files, but here is the disassembly:
The error only occurs on specific webpages (e.g. steamcommunity.com) but not others. Is it possible that some sites just break Qt's API?
compiler: MSVC2013 x86
Qt version: Qt 5.5.0

Turns out that this error is actually a Qt bug.
Its status can be viewed here: Qt Bug Report
Using the new Qt WebEngine Widgets module worked great as a replacement for me.

Related

QT qDebug() does not print anything in IDE console

I need qDebug(), qInfo(), qWarning(), qCritical, or qFatal() to print information to the QTCreator console. Now nothing of it doesn't work. I install QTCreator from repository.
Editing the qtlogging.ini didn't change anything. I added all possible tags to the. pro file.
Qt 5.15.2
Linux user 5.13.15-1-MANJARO #1 SMP PREEMPT x86_64 GNU/Linux
*.pro file:
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
CONFIG += debug
CONFIG += console
*.h file:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QDebug>
#include <QComboBox>
#include <QString>
#include <QtSql>
...
*.cpp file:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
qDebug() << "Check";
ui->setupUi(this);
load();
}
...
that happens because you set CONFIG += console and maybe you didn't uncheck this :
uncheck Run in Terminal.

The program has unexpectedly finished in QT opencv

I know that this has been posted many times,but I could not find the solution from previous posts. I followed tutorial on How to setup Qt and openCV on Windows from wiki Qt.
My .pro file and mainwindows.cpp are shown below. I wanted to open image following the example. What is wrong here? Checked the opencv version and it is the same as libs included. The PATH is also correct.
The cpp file
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat image = cv::imread("C://1.jpg", 1);
cv::namedWindow("My Image");
cv::imshow("My Image", image);
}
MainWindow::~MainWindow()
{
delete ui;
}
and
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = opencvtest
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv-build\bin\libopencv_core451.dll
LIBS += C:\opencv-build\bin\libopencv_highgui451.dll
LIBS += C:\opencv-build\bin\libopencv_imgcodecs451.dll
LIBS += C:\opencv-build\bin\libopencv_imgproc451.dll
LIBS += C:\opencv-build\bin\libopencv_features2d451.dll
LIBS += C:\opencv-build\bin\libopencv_calib3d451.dll
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
When program crashes like that under Qt Creator, and you have extra libraries, the very likely reason is that the extra libraries are missing from the runtime PATH.
In this case, you need to add C:\opencv-build\bin to the PATH. There are at least 3 ways to go about it.
Edit the system environment, so that the relevant directory is always in the system PATH. You need to restart Qt Creator for this change to take effect. This is not the recommended way, unless you actually want these things in there also for other purposes.
You can edit the Build environment of the project under Qt Creator Project view. There's separate configuration for each build type, so you may need to do this to them all separately, which both good and bad. It is good, because then you can have different directory for different builds (for example debug vs relase, MSVC vs MinGW builds). It's bad because it's extra hassle and makes it easier to have something wrong.
You can add it to the run environment in the Qt Creator Project view. Then it will be the same for all build types.
In this case, 3 is probably the way to go.
Qt Creator annoyingly does not display any information about which DLL is missing, it just says the program crashed. This can be solved by instead string the "Qt command prompt" for the correct toolchain from Windows Start menu (search Qt and you should find it). Then go to the built .exe directory and run the .exe. You should now get an error dialog where Windows tells you which DLL it failed to find. Then you can look where that DLL is and add it to the path and try again, until the program starts. After you know the directories using this method, you can then add them to Qt Creator as explained above.

Simple Qt project with openCV instantly crash

I try to use openCV in a Qt project. But my release build instantly crash on launch if I link the release libs of openCV. Debug libs allow the programm to start but the application crashes when I try to use openCV functions (it is known that mixing release/debug in openCV causes some crash).
So I made a simple project and it won't even launch. Both release and debug build crashes and using debugger causes a small window saying 'unexpected CDB exit'.
Here are the source.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test_openCV
TEMPLATE = app
#flags to generate a .map file
QMAKE_LFLAGS_RELEASE +=/MAP
QMAKE_LFLAGS_RELEASE += /debug
SOURCES += main.cpp\
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
INCLUDEPATH += $$PWD
INCLUDEPATH += "D:/openCV/build/include"
#Switching between handbuild and the build I downloaded have no effect.
#I am sure the path are good. Quadra checked.
#LIBS += -L"D:/openCV/build/x64/vc11/lib"
LIBS += -L"D:/openCV/hand_build/lib/Release"
LIBS += -L"D:/openCV/hand_build/lib/Debug"
#disables the "fopen not secure" warning in openCV.
DEFINES += _CRT_SECURE_NO_WARNINGS
win32:CONFIG(release, debug|release): LIBS += -lopencv_core2413 -lopencv_highgui2413 -lopencv_imgproc2413
else:win32:CONFIG(debug, debug|release): LIBS += -lopencv_core2413d -lopencv_highgui2413d -lopencv_imgproc2413d
main.cpp:
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
MainWindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <opencv/cv.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
and MainWindow.cpp:
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Removing this line will causes the program to start normally (guess it won't link the libs if nothing from openCV is used).
cv::Mat image;
}
MainWindow::~MainWindow()
{
delete ui;
}
What I get when launching app:
Starting D:\Colin\build_test_openCV\release\test_openCV.exe...
program suddenly ended
D:\Colin\build_test_openCV\release\test_openCV.exe crashed
I work on Windows 7 / MSCV2012 openGL 64bits / Qt 5.2.1 openGL.
Does anyone see a mistakes I could have made?
I have a similar setup as yours and was getting the exact same problem. The issue was that the path to the corresponding dlls was not defined. These dlls:
opencv_core2411.dll
opencv_highgui2411.dll
opencv_imgproc2411.dll
should be in D:/openCV/hand_build/bin/ (or maybe D:/openCV/hand_build/bin/Release/). Adding another line:
LIBS += -L"D:/openCV/hand_build/bin/Release/"
should work.
I just had a similar issue. The program was crashing because it could not find the appropriate DLL at runtime. Adding the OpenCV directories to my Windows PATH fixed the problem for me.
All items in your build must have been built using the same Visual Studio version, that means:
The Qt install you're using.
OpenCV.
Your code.
Most likely at least one of the above was not built using the same compiler. If OpenCV is linked against Qt, it must have been built against a binary-compatible version of Qt, too.

Qt Widgets FullScreen Margin

I want to create a program that loads google in literally full screen, so I achieved opening my qt program in full screen using w.showFullScreen(); and it works perfectly, however when I add the QWebView and set it to centralWidget like this:
but when I run the program, I get some margins on the sides of the window, in other words the QWebView isn't literally in fullScreen harmoniously with the window which is, it looks like this:
I don't think my code is mistaken but here it is
untitled.pro:
#-------------------------------------------------
#
# Project created by QtCreator 2015-02-07T21:25:42
#
#-------------------------------------------------
CONFIG += release
QT += core gui
QT += webkitwidgets
main.cpp
w.showFullScreen();
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWebKitWidgets>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->webView->load(QUrl("http://www.google.com"));
}
MainWindow::~MainWindow()
{
delete ui;
}
Thank you.
Your central widget have a layout. It's possible that you have layoutLeftMargin, layoutRightMargin, layoutTopMargin, layoutBottomMargin with others values than 0 got in you QtDesigner click on your central widget and at the down of you properties set the margins to 0.

Debug Assertion Failed (unsigned)(c+1) <= 256 (in VideoCapture::open [Qt Creator])

I've been trying to use cv::VideoCapture::open("< path to video file >") in QtCreator (opencv added). Even though the program runs without errors in "bebug mode" (debug build), it gives below runtime error in "release mode" (release build).
Debug Assertion Failed File:
f:/dd/vctools/crt_bld/self_x86/src/isctype.c Line: 56 Expression:
(unsigned)(c+1) <= 256
It is a simple program which uses only cv::VideoCapture::open() [for testing purposes]
Below is the .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:/C/opencv/build/include
INCLUDEPATH += C:/C/opencv/build/include/opencv
LIBS += C:/C/opencv/build/x86/vc10/lib/opencv_highgui240d.lib
LIBS += C:/C/opencv/build/x86/vc10/lib/opencv_highgui240.lib
LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240d.dll
LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240.dll
Below is the Header file
#include <QMainWindow>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
cv::VideoCapture vcap;
};
Below is the .cpp file
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
vcap.open("C:/Users/ANURUDDHA/pedestrians/ThreePastShop2cor.mpg");
}
MainWindow::~MainWindow()
{
delete ui;
}
When I pass an int as the argument to cv::VideoCapture::open() [eg: vcap.open(0)] it runs without errors in both debug and release build and opens webcam successfully. Problem comes only when I pass a String to arguments.
Someone please shed some light on this. Really appreciated.
It looks like you're linking in both debug and release versions of the libs (twice?). That's caused me problems in the past before. Try using only LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240.dll for release builds and LIBS += C:/C/opencv/build/x86/vc10/bin/opencv_highgui240d.dll for debug builds.
Also, 0 is the same as NULL. Probably the library aborts doing whatever it was doing (whether in debug or release) prior to the assert fail. You shouldn't be getting assert fails in release mode, but the fact that you are tells me that the debug library was loaded in your program that you compiled for release mode.
Edit:
Looks like somebody already answered you here:
http://answers.opencv.org/question/15838/videocaptureopenqt-creatordebug-assertion-failed/
I guess I found the answer though it seems kinda ambiguous to me. Anyway, now the program works in release mode.
Hope this might help someone in someway.
I copied dll files inside C:/C/opencv/build/x86/vc10/bin/ to Windows system folder. That is C:\Windows\SysWOW64. In case if someone is using a 32 bit version of Windows it should be System32.