只是试图制作一个简单的网络查看器应用程序,以便我可以在小部件中查看网页,但我收到了错误:
QWidget: Must construct a QApplication before a QPaintDevice
我觉得这是webkit的问题?我正在静态链接这个项目。
主窗口.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
#include <QWebPage>
#include <QtWebKit>
#include "Windows.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWebView *view = new QWebView(parent);
view->load(QUrl("http://google.com/"));
view->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
主文件
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
。轮廓
QT += core gui webkit network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = webkittest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
头文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWebView>
#include <QUrl>
#include <QtPlugin>
#include <QGridLayout>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QMessageBox>
#include <QDialog>
#include <QtWebKit>
class QAction;
class QCheckBox;
class QComboBox;
class QGroupBox;
class QLabel;
class QLineEdit;
class QMenu;
class QPushButton;
class QSpinBox;
class QTextEdit;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
protected:
//void closeEvent(QCloseEvent *event);
//void keyPressEvent(QKeyEvent *);
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
signals:
private slots:
//void onSslErrors(QNetworkReply* reply, const QList<QSslError> &errors);
private:
Ui::MainWindow *ui;
QWebView* m_pWebView;
#endif // MAINWINDOW_H
有什么想法可能导致这种情况吗?