QWebView within QTabWidget: Calling a URL crash the whole Program
-
Hello.
I have created a new QTabWidget and added a TextEditor and a QWebView.
The Problem is, when i try to open a URL, the complete Program crash. I know i am missing something.
Here is part of the Code from mainwindow.h
@
private:
Ui::MainWindow *ui;
QTabWidget *tabWidgetMainWindow;
QWebView *BrowserModule;
QTextEdit *textEditor;
@Part of mainwindow.cpp:
@
//QTextEdit for use in the tabWidgetMainWindow
QTextEdit *textEditor = new QTextEdit;
//The QWebView - But how can i Access+use it within the QTabWidget
QWebView *BrowserModule = new QWebView;//New QTabWidget in the QMainWindow QTabWidget *tabWidgetMainWindow = new QTabWidget(this); tabWidgetMainWindow->setMinimumSize(800,600); tabWidgetMainWindow->addTab(textEditor, "Editor"); tabWidgetMainWindow->addTab(BrowserModule, "Browser"); tabWidgetMainWindow->setCurrentIndex(1); tabWidgetMainWindow->show(); //Activate the whole thing in the last step setCentralWidget(tabWidgetMainWindow); //Keep this thing off as it kills the QTabWidget... //ui->setupUi(this);
@
This Action is used to open the URL (its a Menu Point):
@
void MainWindow::ListeAllerAKPads()
{
QString link = "http://wiki.piratenpartei.de";
BrowserModule->setUrl(link);
//ui->webView->setUrl(link);
//DesktopServices::openUrl(QUrl(link));
}
@Thanks!
The Noob :) -
Hi,
You are shadowing (i.e. calling a local variable the same name as a member variable) your member variables in your constructor so they are not initialized.
-
Thanks for the Description whats going on.
But what is the correct or at least working way to Access the QWebView within the QTabWidget?
When i remove / disable
@
QWebView *BrowserModule;
@from the Header File, i got the Compile Error
"BrowserModule was not declared in this scope" -
As silly as it sounds, just don't shadow your member variables. Use them in the constructor
-
Well i am not sure how to do that but i will look into it. Thanks
-
replace
@QTextEdit *textEditor = new QTextEdit;@by
@textEditor = new QTextEdit;@
-
[quote author="SGaist" date="1391373069"]replace
@QTextEdit *textEditor = new QTextEdit;@by
@textEditor = new QTextEdit;@
[/quote]Wow thanks. You know what: That really works lol
Such a simple change - sometimes i really hate my schizophrenic Brain.Thank You!
-
Well… I try to give solutions that work :D
You're welcome !
Now that it's working, please update your thread title prepending [solved] so other forum users may know a solution has been found :)