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. Vtable issue and moc
QtWS25 Last Chance

Vtable issue and moc

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.1k Views
  • 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.
  • S Offline
    S Offline
    spirit1988
    wrote on last edited by
    #1

    I'm getting this error when I try to run my code:

    editor.cpp:(.text._ZN10MainWindowD2Ev[_ZN10MainWindowD5Ev]+0x3): referencia a `vtable for MainWindow' sin definir

    This is my code:

    @
    #include <QApplication>
    #include <QMainWindow>
    #include <QLabel>
    #include <QWidget>
    #include <QPushButton>
    #include <QVBoxLayout>
    #include <QMenu>
    #include <QMenuBar>
    #include <QFileDialog>

    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    MainWindow(): QMainWindow(0)
    {

        // File menu
        QMenu *file;
        file = this->menuBar()->addMenu("&File");
    
        QAction* open = new QAction("&Open", this);
        connect(open, SIGNAL(triggered()), this, SLOT(openFile&#40;&#41;));
        file->addAction(open);
    
        QAction* save = new QAction("&Save", this);
        // connect(open, SIGNAL(triggered()), qApp, SLOT(quit()));
        file->addAction(save);
    
        QAction* saveAs = new QAction("&Save As", this);
        // connect(open, SIGNAL(triggered()), qApp, SLOT(quit()));
        file->addAction(saveAs);
    
        file->addSeparator();
    
        QAction* quit = new QAction("&Quit", this);
        connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
        quit->setShortcut(tr("CTRL+Q"));
        file->addAction(quit);
    
        // View menu
        QMenu *view;
        view = this->menuBar()->addMenu("&View");
    
        QAction* toolbar = new QAction("&Toolbar", this);;
        toolbar->setCheckable(true);
        toolbar->setChecked(false);
        view->addAction(toolbar);
    
        QAction* points = new QAction("&Walkable points", this);;
        points->setCheckable(true);
        points->setChecked(false);
        view->addAction(points);
        
        QAction* creatures = new QAction("&Creatures Window", this);;
        creatures->setCheckable(true);
        creatures->setChecked(false);
        view->addAction(creatures);  
    
        QAction* dialog = new QAction("&Dialog Window", this);;
        dialog->setCheckable(true);
        dialog->setChecked(false);
        view->addAction(dialog);
    };
    

    public slots:
    void openFile()
    {
    QFileDialog::getOpenFileName( this, tr("Open Document"), QDir::currentPath(), tr("Document files (.doc .rtf);;All files (.)"), 0, QFileDialog::DontUseNativeDialog );

        QString filename = QFileDialog::getOpenFileName( 
            this, 
            tr("Open Document"), 
            QDir::currentPath(), 
            tr("Document files (*.doc *.rtf);;All files (*.*)") );
    
        if( !filename.isNull() )
        {
            qDebug( filename.toAscii() );
        }
    }
    
    void openFiles()
    {
        QStringList filenames = QFileDialog::getOpenFileNames( 
            this, 
            tr("Open Document"), 
            QDir::currentPath(), 
            tr("Documents (*.doc);;All files (*.*)") );
        if( !filenames.isEmpty() )
        {
            qDebug( filenames.join(",").toAscii() );
        }
    }
    
    void openDir()
    {
        QString dirname = QFileDialog::getExistingDirectory( 
            this, 
            tr("Select a Directory"), 
            QDir::currentPath() );
        if( !dirname.isNull() )
        {
            qDebug( dirname.toAscii() );
        }
    }
    
    void saveFile&#40;&#41;
    {
        QString filename = QFileDialog::getSaveFileName( 
            this, 
            tr("Save Document"), 
            QDir::currentPath(), 
            tr("Documents (*.doc)") );
        if( !filename.isNull() )
        {
            qDebug( filename.toAscii() );
        }
    }
    

    };

    int main(int argc, char *argv[ ])
    {
    QApplication app(argc, argv);

    MainWindow win; 
    win.showMaximized();
    return app.exec();
    

    }@

    This is my compile code:

    @
    #!/bin/bash
    qmake -project
    qmake
    make
    @

    I've already tried to delete the .o file and the .pro file. I think the problem may be that I'm doing the class definition and the class declaration in the same file? I wish that's not the problem because I don't want to split this little program in various files.. it's tedious.

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

      Hi and welcome to devnet,

      You need to declare your MainWindow in it's own header in order for moc to make it's job.

      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