QWebView doesnt load any webpage - c++

i am struggling a bit with my project and the thing that is making me really annoyed right now is QWebview. So i tried to create a new project. In this new project all have is blank Qt widget application with one webview added from Qt Designer.
The problem is as the header says, my webview is not willing to load any webpage
i have tried all sorts of possibilities for webpage:
http://google.com
https://google.com
http://www.google.com
https://www.google.com
www.google.com
None of which works, all just give blank page as if about:blank
this is the code
#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);
ui->webView->load(QUrl("http://www.google.com"));
}
MainWindow::~MainWindow()
{
delete ui;
}
I didn't forgot to put QT+= webkitwidgets in pro, also included all libs.
Any suggestions?

Oukey i resolved my problem.
Still dont know what was wrong with QWebView instead i used QWebEngineView and that worked like a charm.
Maybe since its chromium that is the reason.
Thanks all for their inputs.

Related

Qt3DWindow performance issue on Ubuntu 17.10

My problem is that I want to create a Qt3DWindow which I embed in my program using QWidget::createWindowContainer.
I now upgraded to Ubuntu 17.10 but as soon as I add the container widget my CPU load goes up to 100% constant.
This worked already under Ubuntu 16.04 and Windows.
Does anyone know this issue or maybe even have a solution? Or do I have to downgrade to Ubuntu 16.04 again?
A minimally working example is creating a new project in Qt Creator and selecting Qt Widgets Application and, finally, replacing the code in the mainwindow.cpp with the following:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QHBoxLayout>
#include <Qt3DExtras/Qt3DWindow>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->centralWidget->setLayout(new QHBoxLayout());
Qt3DExtras::Qt3DWindow *window = new Qt3DExtras::Qt3DWindow;
QWidget *widget = QWidget::createWindowContainer(window);
ui->centralWidget->layout()->addWidget(widget);
}
MainWindow::~MainWindow()
{
delete ui;
}
Now add 3dextras to QT += core gui in the .pro file of your project and run it. This produces the high CPU load on my machine.

Raspberry Pi 2 Qt app crash

My application randomly crashes. I have used web view to load some URLs and there is always a warning.
qnetworkreplyimplprivate :: error: internal problem, this method must only called ones stack
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setAcceptDrops(true);
web->load(QString("http:my url"));
// QThread *webThread = new QThread;
// web.moveToThread(webThread);
web->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); //Handle link clicks by yourself
connect(web, SIGNAL(linkClicked(QUrl)),this,SLOT(urlCliked(QUrl)));
web->showMaximized();
}
The web pointer is dangling. It should be initialized to point to something. You probably need something like:
web = new QWebView(this);
in your constructor before accessing web as in web->load(QString("http:my url"));
You would also need to include the corresponding header:
#include <QWebView>
I was using Qt version 5.3 on raspberry pi 2 and i have found that i was using improper gcc version within the Qt.
so make sure to use the same Qt version with the correct gcc version.

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.

undefined reference to 'QNetworkAccessManager'

i'm new to QT API and the QT IDE, i was following this tutorial: http://developer.nokia.com/community/wiki/Creating_an_HTTP_network_request_in_Qt, but when i try to compile i get this errors, the usually cause of the problem is: the compiler couldn't
find the .cpp/.lib archive where the code for the methods are, but in this case, the api would be already configured, i can't understand why i'm getting this error, and also i couldn't find the project properties, here is my test code:
#include <QMainWindow>
#include <QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
this is the headers included on the mainwindow.hpp file, now the mainwindow.cpp:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QNetworkAccessManager* nam;
nam = new QNetworkAccessManager(this);
QObject::connect(nam, SIGNAL(finished(QNetworkReply*)),
this, SLOT(finishedSlot(QNetworkReply*)));
QUrl url("http://www.forum.nokia.wiki");
QNetworkReply* reply = nam->get(QNetworkRequest(url));
}
finishedSlot method:
void MainWindow::finishedSlot(QNetworkReply* reply)
{
//nothing
}
so this is the code, if someone can help i'll thank you :)
Do you have QT += network in the .pro project file?
Edit:
fixed typo, was config instead of QT
I solved this for CMake by appending following lines to the CMakeLists.txt:
find_package(Qt5Network REQUIRED)
target_link_libraries(${PROJECT_NAME} Qt5::Network)
If you are using Cmake just add ${QT_QTNETWORK_LIBRARY} to TARGET_LINK_LIBRARIES.

Qt linking problems

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialog.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setCentralWidget(ui->plainTextEdit);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionDoit_triggered()
{
Dialog D;
D.setModal(true);
D.exec();
}
This small piece of code is giving me linker errors LNK2019 and LNK1120
If I remove the three lines in function void MainWindow::on_actionDoit_triggered(), it works. The tutorial I am following didn't warn of linker problems
Apparently, you got it working without changing the code just by re-running qmake explicitly.
The reason is most likely the fact that you modified your qmake project file(s), and QtCreator has issues with knowing when to re-run qmake properly.
There is a long-standing bug about it:
Creator should know when to rerun qmake