Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
C++
#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 :
C++
#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 :
C++
#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 :
C++
#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 :
C++
#include 
#include "mainwindow.h"

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

    return a.exec();
}
Posted

1 solution

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900