The simple test project is here:
Test.pro
#-------------------------------------------------
#
# Project created by QtCreator 2015-08-16T19:28:41
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets webkitwidgets
TARGET = Test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
#-------------------------------------------------
#
# Project created by QtCreator 2015-08-16T19:28:41
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets webkitwidgets
TARGET = Test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
To copy to clipboard, switch view to plain text mode
main.cpp
include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
int code = 0;
do
{
MainWindow w;
w.show();
code = a.exec();
}while(code == 1000);
return 0;
}
include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
int code = 0;
do
{
MainWindow w;
w.show();
code = a.exec();
}while(code == 1000);
return 0;
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_load_complete(); //this is my slot
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#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 slots:
void on_load_complete(); //this is my slot
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWebKitWidgets/QWebView>
#include <QUrl>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->myWebView, SIGNAL(loadFinished(bool)),this, SLOT(on_load_complete(bool)));
ui
->myWebView
->load
(QUrl("https://www.google.com/?gws_rd=ssl"));
}
//this is the implementation of the slot
void MainWindow::on_load_complete(bool b)
{
if(ui->myWebView->url().toString().compare("https://www.google.com/?gws_rd=ssl",Qt::CaseInsensitive) == 0)
{
ui
->myWebView
->load
(QUrl("https://en-maktoob.yahoo.com/?p=us"));
}
else if(ui->myWebView->url().toString().compare("https://en-maktoob.yahoo.com/?p=us",Qt::CaseInsensitive) == 0)
{
//here the application restarts and as expected, it should navigate to google.com and then yahoo.com
//but problem is that at second launch, it stays at google.com, also not loading the google.com page completely!!
//Isnt it strange??
}
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWebKitWidgets/QWebView>
#include <QUrl>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->myWebView, SIGNAL(loadFinished(bool)),this, SLOT(on_load_complete(bool)));
ui->myWebView->load(QUrl("https://www.google.com/?gws_rd=ssl"));
}
//this is the implementation of the slot
void MainWindow::on_load_complete(bool b)
{
if(ui->myWebView->url().toString().compare("https://www.google.com/?gws_rd=ssl",Qt::CaseInsensitive) == 0)
{
ui->myWebView->load(QUrl("https://en-maktoob.yahoo.com/?p=us"));
}
else if(ui->myWebView->url().toString().compare("https://en-maktoob.yahoo.com/?p=us",Qt::CaseInsensitive) == 0)
{
//here the application restarts and as expected, it should navigate to google.com and then yahoo.com
//but problem is that at second launch, it stays at google.com, also not loading the google.com page completely!!
//Isnt it strange??
QApplication::exit(1000);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Just tell me whether this program acts correctly on your system. Honestly, I was testing it and I discovered that it navigates to yahoo.com after first restart, but the page is messed up, and also does not restart again!! It is too slow.
I test it on windows 7.
Just tell me whether it works OK on your system. run it several times.
Thanks in advance

Originally Posted by
anda_skoa
But you are not restarting, you are just recreating a window, no?
Could you not simply delete the web view and recreate it?
Cheers,
_
If so, how can I restart completely??
there is Application.Restart() in C#, but no direct way to achieve this goal in QT.
I will test deleting webview.
Thanks
Bookmarks