使用QWebPage获取运行时错误
Getting runtime errors with QWebPage
我已经创建了一个Qt GUI应用程序,但我还没有涉及任何有关GUI的内容。我已经修改了mainwindow.cpp和项目文件。
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWebPage>
#include <QWebFrame>
QWebPage page;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(page.mainFrame(), SIGNAL(loadFinished(bool)), this, SLOT(pageLoaded1(bool)));
QUrl router("http://192.168.1.1");
page.mainFrame()->load(router);
}
MainWindow::~MainWindow()
{
delete ui;
}
untitled.pr:
#-------------------------------------------------
#
# Project created by QtCreator 2013-05-01T23:48:00
#
#-------------------------------------------------
QT += core gui webkit webkitwidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
main.cpp:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
错误:
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Error!
Program: ...tled-Desktop_Qt_5_0_2_MSVC2010_32bit-Debugdebuguntitled.exe
Module: 5.0.2
File: globalqglobal.cpp
Line: 1977
ASSERT: "!"No style available without QApplication!"" in file kernelqapplication.cpp, line 962
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
---------------------------
此处插入额外字符以绕过字符要求。
在main.cpp
中,确保创建一个应用程序对象,即使不直接使用:
QApplication app;
// Below you can then create the window
编辑
问题是,在创建QApplication
之前,您正在将QWebPage
创建为全局对象。若要解决此问题,请使页面成为MainWindow
类的成员。还要使页面成为指针,否则您将遇到其他问题。
即在mainwindow.h
:中
private:
QWebPage* page;
在mainwindow.cpp
:中
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWebPage>
#include <QWebFrame>
// Remove this!!
// QWebPage page;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Create the page here:
page = new QWebPage(this);
connect(page.mainFrame(), SIGNAL(loadFinished(bool)), this, SLOT(pageLoaded1(bool)));
QUrl router("http://192.168.1.1");
page.mainFrame()->load(router);
}
MainWindow::~MainWindow()
{
delete ui;
}
相关文章:
- 删除指向指针的指针是运行时错误吗
- c++中的指针和运行时错误
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 在同一模拟中使用静脉和静脉_ inet内容时出现运行时错误
- 对单向链表进行排序时出现运行时错误
- 为什么此代码存在运行时错误?
- 你能解释一下什么运行时错误是如何解决它的吗?
- 为什么会出现 gettnig 运行时错误:加载类型为"_Bit_type"(stl_bvector.h) 的空指针?
- 为什么程序在 c++ 中迭代 emtpy 向量时会抛出运行时错误
- 运行时错误:引用绑定到类型为"int"的空指针
- 为什么当 vector 为空时会显示运行时错误?
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 运行时错误:矢量下标超出范围:正在检查空集
- 在Hackerearth上获取运行时错误(SIGSEGV),无法找出代码中的问题
- C++ SDL 初始化所有内容并获取运行时错误
- 尝试获取基分数时出现运行时错误
- 在运行时从应用程序获取PE标头时发生运行时错误
- 使用QWebPage获取运行时错误
- 在代码厨师上获取运行时错误 (SIGSEGV),无法找出代码中的问题
- 在使用相同C++代码的跨平台窗体之间获取运行时错误