Qtwebkit和Webview [英] Qtwebkit and webview

查看:163
本文介绍了Qtwebkit和Webview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我正在使用qtwebkit
我有两种形式.第一种是我的主窗口,有一个按钮.在单击它的插槽中,我想显示我的第二个表单,并使用webview显示一个url(只是一个简单的测试),但是webview不显示该url.怎么了?
这是我的代码:
我的主窗口标题:

 #ifndef MAINWINDOW_H
 #define MAINWINDOW_H

#include   ><  > 

命名空间 Ui {
     class  MainWindow;
}

 class  MainWindow: public  QMainWindow
{
    Q_OBJECT

公共:
    显性 MainWindow(QWidget * parent =  0 );
    〜MainWindow();

私有:
    Ui :: MainWindow * ui;

私有广告位:
    无效 on_pushButton_pressed();
};

#endif//MAINWINDOW_H
</qmainwindow> 




我的主窗口源文件:

 #include   "  mainwindow.h"
 #include   " 
 #include   " 

MainWindow :: MainWindow(QWidget * parent):
    QMainWindow(父级),
    ui( Ui :: MainWindow)
{
    ui-> setupUi();
}

MainWindow ::〜MainWindow()
{
    删除 ui;
}

无效 MainWindow :: on_pushButton_pressed()
{
    webview * w =  webview();
    w-> show();
    w-> setURL(QUrl(" )));



} 



我的webview头文件:

 #ifndef WEBVIEW_H
 #define WEBVIEW_H

#include   ><  > 
 #include   <   qurl  > 

命名空间 Ui {
     class 网络视图;
}

 class 网页视图: public  QMainWindow
{
    Q_OBJECT

公共:
    显性 webview(QWidget * parent =  0 );
    〜webview();
    无效 setURL( const  QUrl&);

私有:
    Ui :: webview * ui;
};

#endif//WEBVIEW_H
</qurl></qmainwindow> 



我的webview源文件:

 #include   "  webview.h"
 #include   " 
 #include   <   qmessagebox  > 

webview :: webview(QWidget * parent):
    QMainWindow(父级),
    ui( Ui :: webview)
{
    ui-> setupUi();
}

webview ::〜webview()
{
    删除 ui;
}

 void  webview :: setURL( const  QUrl& url)
{

    QMessageBox :: information( 0 " " );
    ui-> webView-> load(url);

}
</qmessagebox> 



和我的主文件:

 #include  
 #include   " 

 int  main( int  argc, char  * argv [])
{
    QApplication a(argc,argv);
    MainWindow w;
    w.show();

    返回 a.exec();
} 

解决方案

我找到了答案.对于他们的地址,我应该写"http://www.google.com"(写协议),而不要写"www.google.com"!


hi i am using qtwebkit
i have two forms .the first is my main window and have a push button . in slot clicked of it i want to show my second form and using webview show a url (just as a simple test) but webview does not show the url . what is wrong ?
here is my code :
my main window header :

#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_pressed();
};

#endif // MAINWINDOW_H
</qmainwindow>




my main window source file :

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "webview.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_pressed()
{
    webview *w = new webview();
    w->show();
    w->setURL(QUrl("www.google.com"));



}



my webview header file :

#ifndef WEBVIEW_H
#define WEBVIEW_H

#include <qmainwindow>
#include <qurl>

namespace Ui {
    class webview;
}

class webview : public QMainWindow
{
    Q_OBJECT

public:
    explicit webview(QWidget *parent = 0);
    ~webview();
    void setURL(const QUrl&);

private:
    Ui::webview *ui;
};

#endif // WEBVIEW_H
</qurl></qmainwindow>



my webview source file :

#include "webview.h"
#include "ui_webview.h"
#include <qmessagebox>

webview::webview(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::webview)
{
    ui->setupUi(this);
}

webview::~webview()
{
    delete ui;
}

void webview::setURL(const QUrl& url)
{

    QMessageBox::information(0,"1","2");
    ui->webView->load(url);

}
</qmessagebox>



and my main file :

#include 
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

解决方案

i found the answer . for their addresses i should write "http://www.google.com" ( write the protocol ) instead of "www.google.com" !


这篇关于Qtwebkit和Webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆