Answer the question
In order to leave comments, you need to log in
How to connect Webkit in Qt 5.3.0?
I'm trying to display a website using a webView:
void MainWindow::on_pushButton_clicked()
{
ui->webView->load(QUrl("http://www.trolltech.com/"));
}
13:53:45: Starting: "/usr/bin/make"
g++ -Wl,-rpath,Qt5.3.0/5.3/gcc_64 -Wl,-rpath,/home/fenixsar/Qt5.3.0/5.3/gcc_64/lib -Wl,-rpath-link,Qt5.3.0/5.3/gcc_64/lib -o brouser main.o mainwindow.o moc_mainwindow.o -L./Qt5.3.0/5.3/gcc_64/lib -lQt5WebKit -lQt5Widgets -lQt5Network -lQt5Gui -lQt5Core -lGL -lpthread
mainwindow.o: In function `MainWindow::on_pushButton_clicked()':
/Qt5.3.0/Tools/QtCreator/bin/build-brouser-Desktop_Qt_5_3_0_GCC_64bit-Debug/../brouser/mainwindow.cpp:27: undefined reference to `QWebView::load(QUrl const&)'
mainwindow.o: In function `Ui_MainWindow::setupUi(QMainWindow*)':
/Qt5.3.0/Tools/QtCreator/bin/build-brouser-Desktop_Qt_5_3_0_GCC_64bit-Debug/./ui_mainwindow.h:40: undefined reference to `QWebView::QWebView(QWidget*)'
/Qt5.3.0/Tools/QtCreator/bin/build-brouser-Desktop_Qt_5_3_0_GCC_64bit-Debug/./ui_mainwindow.h:43: undefined reference to `QWebView::setUrl(QUrl const&)'
collect2: error: ld returned 1 exit status
make: *** [brouser] Error 1
13:53:45: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project brouser (kit: Desktop Qt 5.3.0 GCC 64bit)
When executing step 'Make'
13:53:45: Elapsed time: 00:00.
QT += core gui webkit network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = brouser
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
#include <QtWebKitWidgets/QWebView>
#include <QtWebKit>
Answer the question
In order to leave comments, you need to log in
Tried to include different libraries:Firstly, who told you that libraries in C ++ are connected in this way? So only declarations of classes and their methods are connected. You will not connect libraries to the project in this way, and therefore you will get a natural linking error " undefined reference to ... ". This is completely logical, since you included declarations, but their implementation did not. By the way, you do not need these lines at all, delete them, they will not have the desired effect, since they are already in "ui_MainWindow.h", open this file and examine its header.
#include
#include
#include <QtWebKitWidgets/QWebView>
#include <QtWebKit>
#-------------------------------------------------
#
# Project created by QtCreator 2014-06-09T02:41:10
#
#-------------------------------------------------
QT += core gui webkit webkitwidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled3
TEMPLATE = app
SOURCES += main.cpp\
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#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;
private slots:
void on_pushButton_clicked();
};
#endif // MAINWINDOW_H
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ui->webView->setUrl(QUrl("http://www.habrahabr.ru"));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question