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. SegFault accessing `ui->tabWidget` but there is warning about vtable entries
Forum Updated to NodeBB v4.3 + New Features

SegFault accessing `ui->tabWidget` but there is warning about vtable entries

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 520 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.
  • enjoysmathE Offline
    enjoysmathE Offline
    enjoysmath
    wrote on last edited by
    #1

    Warnings I'm getting and trying to correct:

    dd3bb940-5107-421d-96ca-e85c0a9a528d-image.png

    Upon building a second time, it builds but segfaults in this function:

    void MainWindow::zoomCurrentWidget(int times)
    {
        auto widget = ui->tabWidget->currentWidget();
    
        if (widget) {
            auto view = dynamic_cast<ZoomableView*>(widget);
    
            if (view)
                view->zoomTimes(times);
        }
    }
    

    My mainwindow.h is :

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
        void addTabWidget(QWidget* widget, const QString& tabName);
    
    private slots:
        void on_actionZoom_In_triggered();
        void on_actionZoom_Out_triggered();
    
        void zoomCurrentWidget(int times);
    
    private:
        Ui::MainWindow *ui;
    };
    #endif // MAINWINDOW_H
    

    I've also tried: virtual ~MainWindow() and virtual ~MainWindow() override and ~MainWindow() override. All the same issues.

    It is supposed to be straightforward to work with UI Forms, but I'm getting segfaults...

    https://github.com/enjoysmath
    https://math.stackexchange.com/users/26327/exercisingmathematician

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #12

      Then you killed the tabWidget somewhere else already.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      enjoysmathE 1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Where do you initialize ui?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • enjoysmathE Offline
          enjoysmathE Offline
          enjoysmath
          wrote on last edited by enjoysmath
          #3
          MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)
              , ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          }
          

          Code generated by Qt Creator. Also, it's not because I have zoomCurrentWidget under private slots . I put it under public slots and same error.

          https://github.com/enjoysmath
          https://math.stackexchange.com/users/26327/exercisingmathematician

          JonBJ 1 Reply Last reply
          0
          • enjoysmathE enjoysmath
            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            }
            

            Code generated by Qt Creator. Also, it's not because I have zoomCurrentWidget under private slots . I put it under public slots and same error.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @enjoysmath
            For this kind of problem, have you at least tried emptying out the whole build directory and rebuilding from scratch? Perhaps not your case, but this has solved quite a few "funnies" from other people in the past, worth ensuring.

            enjoysmathE 1 Reply Last reply
            2
            • JonBJ JonB

              @enjoysmath
              For this kind of problem, have you at least tried emptying out the whole build directory and rebuilding from scratch? Perhaps not your case, but this has solved quite a few "funnies" from other people in the past, worth ensuring.

              enjoysmathE Offline
              enjoysmathE Offline
              enjoysmath
              wrote on last edited by
              #5

              @JonB Nope that didn't solve it :)

              https://github.com/enjoysmath
              https://math.stackexchange.com/users/26327/exercisingmathematician

              JoeCFDJ 1 Reply Last reply
              1
              • enjoysmathE enjoysmath

                @JonB Nope that didn't solve it :)

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by JoeCFD
                #6

                @enjoysmath

                1. click make clean and rebuild your app( better cd the build dir and do make distclean, then click run qmake)
                2. Set a break point at the beginning of that func and show which line causes crashes.
                1 Reply Last reply
                2
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  Hi
                  It all looks pretty normal.

                  If you open one of the examples and run. Does it compile without any such errors ?

                  Do you link any other libs via the pro file ?

                  I have seen this error message with some nasty pointer errors.
                  Do you do anything interesting with any of the Widgets ?
                  Like keeping them in a list and also insert into a form or anything like that ?

                  enjoysmathE 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    Hi
                    It all looks pretty normal.

                    If you open one of the examples and run. Does it compile without any such errors ?

                    Do you link any other libs via the pro file ?

                    I have seen this error message with some nasty pointer errors.
                    Do you do anything interesting with any of the Widgets ?
                    Like keeping them in a list and also insert into a form or anything like that ?

                    enjoysmathE Offline
                    enjoysmathE Offline
                    enjoysmath
                    wrote on last edited by
                    #8

                    @mrjj Nope, nothing unusual. What's causing the vtable errors?

                    https://github.com/enjoysmath
                    https://math.stackexchange.com/users/26327/exercisingmathematician

                    mrjjM 1 Reply Last reply
                    0
                    • enjoysmathE enjoysmath

                      @mrjj Nope, nothing unusual. What's causing the vtable errors?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      Hi
                      well actually the normal one is
                      undefined reference to `vtable for
                      which can be caused by not implementing virtual functions or lack
                      QOBJECT macro among other things.

                      But this error
                      cant find Linker symbol for virtual table
                      seems to be linked to both virtual function and dangling pointers.

                      If i had to guess , it would be on some kind of pointer error.

                      When it crashes, the call stack gives no hint on what it was doing ?

                      1 Reply Last reply
                      2
                      • enjoysmathE Offline
                        enjoysmathE Offline
                        enjoysmath
                        wrote on last edited by enjoysmath
                        #10
                        
                         void MainWindow::zoomCurrentWidget(int times)
                         {
                             auto widget = ui->tabWidget->currentWidget();
                         
                             if (widget) {
                                 auto view = dynamic_cast<ZoomableView*>(widget);
                         
                                 if (view)
                                     view->zoomTimes(times);
                             }
                        }
                        

                        @mrjj It's in this function where the SegFault happens. It was usually on the first line, but later the Qt Creator had me believing it was also happening further down.

                        https://github.com/enjoysmath
                        https://math.stackexchange.com/users/26327/exercisingmathematician

                        1 Reply Last reply
                        0
                        • enjoysmathE Offline
                          enjoysmathE Offline
                          enjoysmath
                          wrote on last edited by
                          #11

                          @mrjj It's definitely the first line. It doesn't return a working pointer to the QTabWidget, although QtCreator, when you hover over the code in Debug mode, shows that it's a QTabWidget* typed value. So there is a bug with QtCreator. I'm doing nothing special to induce this bug. Does this mean I have to go back to PyQt5 to finish my project? I thought C++ would be a lot nicer for handling large graphics scenes, but apparently there are just too many bugs.

                          https://github.com/enjoysmath
                          https://math.stackexchange.com/users/26327/exercisingmathematician

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #12

                            Then you killed the tabWidget somewhere else already.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            enjoysmathE 1 Reply Last reply
                            1
                            • enjoysmathE Offline
                              enjoysmathE Offline
                              enjoysmath
                              wrote on last edited by
                              #13

                              @Christian-Ehrlicher that's the first time I'm accessing the QTabWidget.

                              https://github.com/enjoysmath
                              https://math.stackexchange.com/users/26327/exercisingmathematician

                              1 Reply Last reply
                              0
                              • Christian EhrlicherC Christian Ehrlicher

                                Then you killed the tabWidget somewhere else already.

                                enjoysmathE Offline
                                enjoysmathE Offline
                                enjoysmath
                                wrote on last edited by
                                #14

                                @Christian-Ehrlicher

                                Okay, you were right :)

                                I was doing this:

                                ```
                                

                                MainWindow w;
                                w.setCentralWidget(&view);
                                w.show();

                                
                                Which would of course wipe out the QWidget created from the UI Designer.  Thank you!
                                
                                :)

                                https://github.com/enjoysmath
                                https://math.stackexchange.com/users/26327/exercisingmathematician

                                mrjjM 1 Reply Last reply
                                2
                                • enjoysmathE enjoysmath

                                  @Christian-Ehrlicher

                                  Okay, you were right :)

                                  I was doing this:

                                  ```
                                  

                                  MainWindow w;
                                  w.setCentralWidget(&view);
                                  w.show();

                                  
                                  Which would of course wipe out the QWidget created from the UI Designer.  Thank you!
                                  
                                  :)
                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #15

                                  @enjoysmath
                                  Hi
                                  Just as a note:

                                  • Does this mean I have to go back to PyQt5 to finish my project?

                                  Python version is a binding using the c++ classes so if it was a Qt bug same thing would happen in PyQt5.

                                  enjoysmathE 1 Reply Last reply
                                  1
                                  • mrjjM mrjj

                                    @enjoysmath
                                    Hi
                                    Just as a note:

                                    • Does this mean I have to go back to PyQt5 to finish my project?

                                    Python version is a binding using the c++ classes so if it was a Qt bug same thing would happen in PyQt5.

                                    enjoysmathE Offline
                                    enjoysmathE Offline
                                    enjoysmath
                                    wrote on last edited by
                                    #16

                                    @mrjj @Christian-Ehrlicher @JonB @JonB

                                    Thanks all who helped me solve this. I will make it my duty to write an awesome software tool for my users.

                                    -EnjoysMath

                                    https://github.com/enjoysmath
                                    https://math.stackexchange.com/users/26327/exercisingmathematician

                                    1 Reply Last reply
                                    1

                                    • Login

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