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. undefined reference to `vtable for shutdown'
Forum Updated to NodeBB v4.3 + New Features

undefined reference to `vtable for shutdown'

Scheduled Pinned Locked Moved Solved General and Desktop
60 Posts 6 Posters 8.6k Views 2 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.
  • JoeCFDJ JoeCFD

    are you building on Linux, right? If yes, change your class name with ShutdownWindow (do not forget the ui file).

    SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #47

    @JoeCFD, I've changed the class names, do the filenames also need to be changed?

    Kind Regards,
    Sy

    JoeCFDJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      @JoeCFD, I've changed the class names, do the filenames also need to be changed?

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

      @SPlatten better. But not necessary. Try to build to see if it works.

      1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        are you building on Linux, right? If yes, change your class name with ShutdownWindow (do not forget the ui file).

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #49

        @JoeCFD , I was hoping this was going to solve the problems, but sadly not, the reports messages are the same just "shutdownWindow" now instead of "shutdown".

        Kind Regards,
        Sy

        JoeCFDJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @JoeCFD , I was hoping this was going to solve the problems, but sadly not, the reports messages are the same just "shutdownWindow" now instead of "shutdown".

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

          @SPlatten something weird is going here. This means you can not add any class to your project. You must have other classes. Copy it and change its name to ShutdownWindow. Add it to your project. May I see your
          make VERBOSE=1 output?

          SPlattenS 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @SPlatten something weird is going here. This means you can not add any class to your project. You must have other classes. Copy it and change its name to ShutdownWindow. Add it to your project. May I see your
            make VERBOSE=1 output?

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #51

            @JoeCFD , could this be a namespace / scope issue? I don't have a lot of experience with namespace and the pitfalls of use.

            The C module where these are used are defined in:

            namespace a {
            namespace b {
            namespace c {
            static void shutdownNotice(const char* cpszText) {
                shutdownWindow w(cpszText);
                w.setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
                w.move(QApplication::desktop()->screen()->rect().center() - w.frameGeometry().center());
                w.show();
            }
            ...
            

            In the shutdown.h and shutdown.cc files there are no namespaces except in the header:

            namespace Ui {
                class shutdownWindow;
            }
            

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • SPlattenS SPlatten

              Just for completeness, here is the actual content of the CMakeLists.txt file:

              cmake_minimum_required(VERSION 2.8.10)
              include (flexelint) 
              
              set (CMAKE_AUTOUIC ON)
              set (CMAKE_AUTOMOC ON)
              set (CMAKE_AUTORCC ON)
              set (CMAKE_INCLUDE_CURRENT_DIR ON)
              
              set (FORMS shutdown_ui)
              set (HEADERS shutdown.h
                           ui_shutdown.h)
              set (sources shutdown.cc)
              set (output vip_backend)
              add_library(${output} STATIC ${sources})
              find_package(Qt4 REQUIRED)
              include(${QT_USE_FILE})
              foreach(loop_var ${QT_LIBRARIES})
                string(REPLACE lib64 lib32 loop_var ${loop_var})
                set(QT_LIBRARIES_32 ${QT_LIBRARIES_32} ${loop_var})
              endforeach(loop_var)
              qt4_wrap_ui(UI_HEADERS ${FORMS})
              qt4_wrap_cpp(MOC_SRCS ${HEADERS})
              target_link_libraries(${output} ${QT_LIBRARIES_32})
              add_flint(${output})
              

              I have no idea what flexelint is or what it does, same is true of add_flint(${output}).

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by Christian Ehrlicher
              #52

              @SPlatten said in undefined reference to `vtable for shutdown':

              set (HEADERS shutdown.h
              ui_shutdown.h)

              ui_shutdown.h must not be here. And there must not be such a header file in the source directory!

              qt4_wrap_ui(UI_HEADERS ${FORMS})
              qt4_wrap_cpp(MOC_SRCS ${HEADERS})

              This does nothing as long as you don't add the output (UI_HEADERS, MOC_SRCS) to your add_library() call ...

              set (FORMS shutdown_ui)

              I doubt this is correct.

              You have always to have virtual in front of a destructor. Otherwise, you may have unpleasant memory leak in your apps.

              This is wrong - the shutdown dtor is virtual by default because QObject's dtor is already virtual

              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
              3
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by SPlatten
                #53

                I'm now pretty sure the problem is namespace related, but I don't know how to resolve it.

                In the source file where the static function shutdownNotice is called it is inside three levels of namespace:

                #include "shutdown.h"
                #include <QApplication>
                #include <QDesktopWidget>
                
                namespace a {
                namespace b {
                namespace c {
                
                static void shutdownNotice(const char* cpszText) {
                    Ui::shutdownWindow w(cpszText);
                    w.setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
                    w.move(QApplication::desktop()->screen()->rect().center()
                           - w.frameGeometry().center());
                    w.show();
                }
                ...
                

                In the header that contains the shutdownWindow class:

                shutdown.h:

                #ifndef SHUTDOWN_H
                #define SHUTDOWN_H
                
                #include <QMainWindow>
                
                namespace Ui {
                    class shutdownWindow;
                }
                
                class shutdownWindow : public QMainWindow {
                    Q_OBJECT
                
                public:
                    explicit shutdownWindow(const char* cpszText, QWidget* pParent = 0);
                    ~shutdownWindow();
                
                private:
                    Ui::shutdownWindow* ui;
                };
                #endif // SHUTDOWN_H
                

                shutdown.cc

                #include "shutdown.h"
                #include "ui_shutdown.h"
                
                shutdownWindow::shutdownWindow(const char* cpszText, QWidget* pParent) :
                    QMainWindow(pParent),
                    ui(new Ui::shutdownWindow) {
                    ui->setupUi(this);
                    if ( cpszText ) {
                        ui->plblText->setText(cpszText);
                    }
                }
                
                shutdownWindow::~shutdownWindow() {
                    delete ui;
                }
                

                With this set-up, the errors are:

                In function 'void a::b::c::shutdownNotice(const char*)':
                error: variable `Ui::shutdownWindow w' has initializer but incomplete type
                

                Kind Regards,
                Sy

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

                  You did not include the required file.

                  That said, you are using it wrongly. It's not Ui::shutdownWindow that you want to instantiate but just shutdownWindow.

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

                  SPlattenS 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    You did not include the required file.

                    That said, you are using it wrongly. It's not Ui::shutdownWindow that you want to instantiate but just shutdownWindow.

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by SPlatten
                    #55

                    @SGaist , where? what line? because I believe the Ui::shutdownWindow is just used as a forward declaration, also this code was copied from an auto generated header and source file by Qt Creator...create a blank UI class in Qt Creator with a single label, removing the menu and status bar and this is pretty much what you get.

                    Just to complete the picture the gcc version is Gentoo 4.6.3 p1.13, pie-0.5.2)

                    Kind Regards,
                    Sy

                    1 Reply Last reply
                    0
                    • SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #56

                      I finally found and fixed the issue, which turned out to be not code related at all. The problem was in the CMakeLists.txt file, the build structure here is over complicated and there were two instances of the same file in a slightly different folder structure, unfortunately I had been editing the wrong file, having realised this and moved onto the correct file, everything is now A ok!

                      Kind Regards,
                      Sy

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @SPlatten said in undefined reference to &#x60;vtable for shutdown':

                        ../../(shutdown.cc.o): In function `shutdown::shutdown(char const*, QWidget*)':

                        Note that this .o file is being found in ../.. from where you are/the compiler is being run. Is that indeed correct for you, and where you have deleting files from? Do you by any chance have any other shutdown.cc.o file lying around anywhere from, say, the whole of ../.. downward?

                        I have no experience of " I have added a class one of the libraries which are built with cmake". But when you do a complete rebuild I am expecting you to see among the commands:

                        • A uic run on on shutdown.ui, producing ui_shutdown.h.
                        • A cc (or whatever) compilation run on shutdown.cc, producing shutdown.o.
                        • A cc on moc_shotdown.cc, or similar, producing <can't recall>.
                        • Some kind of ld (or maybe cc) doing the linking. It will involve shutdown.cc.o, I can't remember how moc works, whether there is a moc_shutdown.cc.o or just the moc_shutdown.h or whatever source file.

                        This is not for you to paste the whole output here, it's for you to look at just to verify. It ought be correct anyway.

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

                        @SPlatten

                        @JonB said in undefined reference to &#x60;vtable for shutdown':

                        Do you by any chance have any other shutdown.cc.o file lying around anywhere from, say, the whole of ../.. downward?

                        You really might have spotted a duplicate shutdown.cc while checking for this.

                        And/or, when you were recompiling each time the Compilation Output (or whatever) pane shows you the build commands being executed, could you not see this situation from that?

                        SPlattenS 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @SPlatten

                          @JonB said in undefined reference to &#x60;vtable for shutdown':

                          Do you by any chance have any other shutdown.cc.o file lying around anywhere from, say, the whole of ../.. downward?

                          You really might have spotted a duplicate shutdown.cc while checking for this.

                          And/or, when you were recompiling each time the Compilation Output (or whatever) pane shows you the build commands being executed, could you not see this situation from that?

                          SPlattenS Offline
                          SPlattenS Offline
                          SPlatten
                          wrote on last edited by SPlatten
                          #58

                          @JonB , the build process is a complete night-mare, Eclipse is used to edit the source, then a lot of cmake files and scripts. I wish it was all done with QtCreator.

                          Kind Regards,
                          Sy

                          JoeCFDJ 1 Reply Last reply
                          0
                          • SPlattenS SPlatten

                            @JonB , the build process is a complete night-mare, Eclipse is used to edit the source, then a lot of cmake files and scripts. I wish it was all done with QtCreator.

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

                            @SPlatten QtCreator supports CMake. And Qt is built with CMake. Therefore, it may be a good idea to go with CMake down the road. Simply get used to it. I normally have both pro and cmake. From command line or on the server, cmake is used. In QtCreator debugging pro file is used.

                            I also did not see your VERBOSE output which may be able to provide more error info.

                            And your cmake version is too old. The newer version may be able to offer more info. Also you may need to be able to dig into build/CMakeFiles to check link and flags settings in the future.

                            1 Reply Last reply
                            0
                            • SPlattenS SPlatten

                              I finally found and fixed the issue, which turned out to be not code related at all. The problem was in the CMakeLists.txt file, the build structure here is over complicated and there were two instances of the same file in a slightly different folder structure, unfortunately I had been editing the wrong file, having realised this and moved onto the correct file, everything is now A ok!

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #60

                              @SPlatten said in undefined reference to &#x60;vtable for shutdown':

                              nd there were two instances of the same file in a slightly different folder structure

                              again: the ui_foo.h file must not be in the source directory but is created by cmake/uic! Remove such files from your source tree and fix your CMakeLists.txt

                              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
                              0

                              • Login

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