PDA

View Full Version : QtWebKit-Tabs



Viper666
1st July 2012, 14:55
Hello,
I make simple browser but i have trouble. I want to make tabs but i don't know how. I try some things for example
void MainWindow::AddTab(QUrl url)
{
view = new WebView(this);
tabWidget->addTab(view,"");
view->load(url);
}
It's good but now SIGNALS and SLOTS don't know whitch view is SIGNAL and which SLOT.
Thanks for answer
SORRY FOR MY ENGLISH I'M NOT FROM USA OR ENGLAND

ChrisW67
2nd July 2012, 07:58
It's good but now SIGNALS and SLOTS don't know whitch view is SIGNAL and which SLOT.
Thanks for answer
What exactly is the question? Which signals and slots do you mean? How are they connected?

SORRY FOR MY ENGLISH I'M NOT FROM USA OR ENGLAND
I am not either ;)

Viper666
2nd July 2012, 14:31
What exactly is the question? Which signals and slots do you mean? How are they connected?

The whole program is based on SIGNALS and SLOTS

MainWindow.cpp - connections

connect(webView->page->networkAccessManager(),SIGNAL(sslErrors(QNetworkRe ply*,QList<QSslError>)),
this,SLOT(sslErrorHandler(QNetworkReply*,QList<QSslError>)));
connect(urlEdit,SIGNAL(returnPressed()),this,SLOT( GoToUrl()));
connect(backPage,SIGNAL(triggered()),webView,SLOT( back()));
connect(nextPage,SIGNAL(triggered()),webView,SLOT( forward()));
connect(urlEdit->refresh,SIGNAL(clicked()),webView,SLOT(reload()));
connect(urlEdit->bookmarks,SIGNAL(clicked()),this,SLOT(AddBookmark( )));
connect(urlEdit->stop,SIGNAL(clicked()),webView,SLOT(stop()));
connect(goHome,SIGNAL(triggered()),this,SLOT(GoHom e()));
connect(webView,SIGNAL(urlChanged(QUrl)),this,SLOT (urlChanged(QUrl)));
connect(webView,SIGNAL(linkClicked(QUrl)),this,SLO T(linkClicked(QUrl)));
connect(webView,SIGNAL(statusBarMessage(QString)), this,SLOT(statusBarMessage(QString)));
connect(webView,SIGNAL(loadStarted()),this,SLOT(lo adStarted()));
connect(webView,SIGNAL(loadProgress(int)),this,SLO T(loadProgress(int)));
connect(webView,SIGNAL(loadFinished(bool)),this,SL OT(loadFinished(bool)));
connect(searchLine->search,SIGNAL(clicked()),this,SLOT(Search()));
connect(searchLine,SIGNAL(returnPressed()),this,SL OT(Search()));

and only webView connections - back, forward, title changed - tabs name, url changed

connect(webView,SIGNAL(urlChanged(QUrl)),this,SLOT (urlChanged(QUrl)));
connect(webView,SIGNAL(linkClicked(QUrl)),this,SLO T(linkClicked(QUrl)));
connect(webView,SIGNAL(statusBarMessage(QString)), this,SLOT(statusBarMessage(QString)));
connect(webView,SIGNAL(loadStarted()),this,SLOT(lo adStarted()));
connect(webView,SIGNAL(loadProgress(int)),this,SLO T(loadProgress(int)));
connect(webView,SIGNAL(loadFinished(bool)),this,SL OT(loadFinished(bool)));

And question: I have troubles with connection for example i have two tabs and now i click back and connection don't know which webview must go back :D

Viper666
2nd July 2012, 17:42
Do you understand me what i mean?

ChrisW67
3rd July 2012, 04:19
Do you understand me what i mean?
Yes, but I do need to sleep from time to time.

Clearly if you connect the back button to only one QWebView then only one QWebView can be affected. Connect your back button to a slot of your own that looks up the current tab widget (QTabWidget::currentWidget()), qobject_cast it to QWebView*, and call back() on that widget. The same logic goes for the forward button etc.

Viper666
3rd July 2012, 11:19
I start working with it.
Thanks for help and



I am not either ;)
I'm not from english speaks country and I learnt speak English only in the school only 3 years (It long time, but in school don't learn speak a lot :D and so I'm happy that you understand me )
I'm going to try it but one thing isn't for me clearly in mainwindow.cpp i let any connections and i make my own slot for http://doc.qt.nokia.com/4.7-snapshot/qtabwidget.html#currentChanged and here i can give
widget = tabWidget->currentWidget();
view = qobject_cast<WebView*>(widget);//i wrote this from head. Here can be any errors
//and here i give here view's connections
Right???
or It will working when all connections will be in constructor ??

ChrisW67
4th July 2012, 00:04
Your English is quite understandable.

In your main window constructor you create your UI (back, forward buttons etc.) and connect the buttons to slots defined in the main window class. In the slot you use the code you started above and then you directly call the back() or forward() functions of the web view. There are no signal-slot connections to the web view for navigation. Something like;


MainWindow::MainWindow(QWidget *p) : QWidget(p)
{
setupUi();

connect(ui->backButton, SIGNAL(clicked()), SLOT(doBack()));
connect(ui->forwardButton, SIGNAL(clicked()), SLOT(doForward()));
...
}


void MainWindow::doBack()
{
QWidget *widget = tabWidget->currentWidget();
QWebView *view = qobject_cast<QWebView*>(widget);
if (view) // in case you have a tab that is not a QWebView
view->back();
}

Viper666
4th July 2012, 11:49
Your English is quite understandable.

So I'm glad.
And thanks for all answers they were very helpful. :)

Viper666
17th July 2012, 13:45
oh I started work with it and now go back and so work fine but for example TitleChanged don't work- only first webview(default webview- in constructor) emit signal second webview doesn't work, it doesn't emit signal and one thing when i use tabwidget first 3 actions don't react:crying:

ChrisW67
19th July 2012, 03:29
oh I started work with it and now go back and so work fine but for example TitleChanged don't work- only first webview(default webview- in constructor) emit signal second webview doesn't work, it doesn't emit signal
Sure it does; when the widget's displayed web page title changes. What have you connected it to? What are you doing to update the window title when you switch between tabs? I could guess all day. How about describing, or better showing, the code you have used and explaining what you expected it to do, what it is doing, and why you think that might be.


and one thing when i use tabwidget first 3 actions don't react:crying:
No idea what you are talking about.

Viper666
19th July 2012, 12:47
I can this make throw tabwidget signal currentchanged and make my own slot bu how i can reload only title of page??? i will send code but now i'm not at my PC.
And i don't now when i make tab widget like this
view = new WebView(this);
tab = new QTabWidget(view);
ui->toolbar->addAction(goBack);....
first 3 actions don't react(no action but area where are they don't react)
my constructor when it don't work
urlLine = new UrlLine(this);
searchLine = new SearchLine(this);

goHome = new QAction(QIcon(":/Icons/Home.png"),"http://google.sk",this);
goBack = new QAction(QIcon(":/Icons/Back.png"),"Back",this);
goForward = new QAction(QIcon(":/Icons/Forward.png"),"Forward",this);
downloads = new QAction(QIcon(":/Icons/Downloads.png"),"Downloads",this);
spacer = new QWidget(this);
spacer->setMaximumSize(5,5);
spacer->setMinimumSize(5,5);
currentWidget = new QWidget(this);


ui->toolBar->addAction(goBack);
ui->toolBar->addAction(goForward);
ui->toolBar->addSeparator();
ui->toolBar->addWidget(urlLine);
ui->toolBar->addWidget(spacer);
ui->toolBar->addWidget(searchLine);
ui->toolBar->addAction(goHome);

Web = new WebView(this);
tabWidget = new QTabWidget(Web);
setCentralWidget(tabWidget);
tabWidget->insertTab(TabIndex,Web,"google.com");

Web->load(QUrl("http://google.com"));

Viper666
20th July 2012, 18:32
if you don't understand me say i try again it

ChrisW67
21st July 2012, 00:33
When you add a new tab connect the QWebView::titleChanged() signal to a common slot that either changes the relevant tab text, main window title bar text, or both. You can set the text on the tab with QTabWidget::setTabText() or in the main window title bar with QWidget::setWindowTitle(). You can determine which tab corresponds to the QWebView sender by using QTabWidget::indexOf().

Viper666
21st July 2012, 11:55
i try it but is my function correct???
void MainWindow::OpenInNewTab(QUrl url)
{
Web = new WebView(this);
TabIndex++;
tabWidget->insertTab(TabIndex,Web,"(untitled)");
tabWidget->setCurrentIndex(TabIndex);
QMessageBox::information(this,"as",url.toString());
Web->load(url);
//and here i add connect
}

Viper666
21st July 2012, 15:25
it work very fine thanks and sorry if i wrote some stupid things i'm 14 years old and i'm fighting with my english and my logic :D

Viper666
23rd July 2012, 20:11
and one thing for example http://www.google.com/imgres?num=10&hl=en&biw=1280&bih=681&tbm=isch&tbnid=Nhb210LtVhzVMM:&imgrefurl=http://justgotplayed.blogspot.com/2012/01/hi.html&docid=h6NYCFbLW3rTGM&imgurl=http://1.bp.blogspot.com/-GiUR2zmSrn4/TwBD-BlkPjI/AAAAAAAAAVU/LgSWZLKAe5k/s1600/hi.jpg&w=400&h=400&ei=WZMNUNuSOcmD4gTgk53OCg&zoom=1&iact=rc&dur=321&sig=100958105349359531624&page=1&tbnh=148&tbnw=168&start=0&ndsp=18&ved=1t:429,r:5,s:0,i:90&tx=113&ty=32 show page but the image isn't show like in firefox show only pages with images no only image

Viper666
24th July 2012, 16:30
someone told me that i can make tabs with threads it is good idea or bad idea

ChrisW67
25th July 2012, 03:59
You do not need threads to make a basic tabbed browser and they will only cause you further heartache.

I did not understand what you were talking about regarding images.

Viper666
25th July 2012, 11:33
When you browse images on google and click on it show image and website in background in my browser show only the websites in background imaga don't show

Viper666
31st July 2012, 18:59
:D you said it :D ok i made some test with thread and i want in ~MainWindow stop thread so i make static funcion (i will start thread in my TabWidget class)
static void DestroyThread()
{
exit(0);
}
but now i have 1 error i don't know what i should do error = cannot call member function 'void QThread::exit(int)' without object. It is good idea. Delete it all threads? or have you better idea? :D
Thanks

Viper666
1st August 2012, 13:26
ok i make it with closeEvent

Viper666
2nd August 2012, 12:29
but can you help me with this http://www.qtcentre.org/threads/38582-Custom-TabWidget-button pls now it is my main problem

Viper666
5th August 2012, 18:08
oh threads make me troubles so i want use thread to loading, goBack .etc but i don't know how i can give the WebView to the thread. i can't make it with parent because parent is in else thread i try make new Widget in thread and give the widget from thread to the window but same error with parents

Viper666
8th August 2012, 10:49
Can you help me QWebSetting::iconForUrl() always return same icon which is in my resource file
Thanks