Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebView within QTabWidget: Calling a URL crash the whole Program
Forum Updated to NodeBB v4.3 + New Features

QWebView within QTabWidget: Calling a URL crash the whole Program

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MeerMusikM Offline
    MeerMusikM Offline
    MeerMusik
    wrote on last edited by
    #1

    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 :)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • MeerMusikM Offline
        MeerMusikM Offline
        MeerMusik
        wrote on last edited by
        #3

        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"

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          As silly as it sounds, just don't shadow your member variables. Use them in the constructor

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • MeerMusikM Offline
            MeerMusikM Offline
            MeerMusik
            wrote on last edited by
            #5

            Well i am not sure how to do that but i will look into it. Thanks

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              replace
              @QTextEdit *textEditor = new QTextEdit;@

              by

              @textEditor = new QTextEdit;@

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • MeerMusikM Offline
                MeerMusikM Offline
                MeerMusik
                wrote on last edited by
                #7

                [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!

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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 :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved