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. error: undefined reference to `non-virtual thunk to MainWindow::~MainWindow()'

error: undefined reference to `non-virtual thunk to MainWindow::~MainWindow()'

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 2.8k 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.
  • D Offline
    D Offline
    deleted286
    wrote on last edited by
    #1

    I could not solve these problems. What is my mistake?
    Ekran görüntüsü 2021-01-11 000659.png

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QtWidgets/QMainWindow>
    #include <QMainWindow>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        ui->setupUi(this);
    
        // Initialize the new objects
        myThreadObject = new MyThread();
        myQThread = new QThread();
    
        // Move to new thread
        myThreadObject->moveToThread(myQThread);
    
        // connect signal and slots
        connect(this, &MainWindow::startWriting, myThreadObject, &MyThread::writeData);
        connect(myThreadObject, &MyThread::writingDone, this, &MainWindow::writingDoneByThread);
    
        // Start the new thread
        myQThread->start();
    }
    

    mythread.cpp

    #include "mythread.h"
    #include "mainwindow.h"
    #include <QtCore>
    #include <QDebug>
    #include <QFile>
    #include <QTimer>
    #include <QThread>
    #include <QMutex>
    #include <QQueue>
    #include <QMessageBox>
    #include <QApplication>
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QMainWindow>
    #include <QFileDialog>
    #include <QMainWindow>
    
    
    QFile file("C:/Users/ilknu/Documents/MyThread/deneme.txt");
    
    
    MyThread::MyThread(QObject* parent)
        : QThread(parent)
    
    {
    
    }
    
    MyThread::~MyThread() {
    
    }
    
    
    void MyThread::writeData()
    {
    
        QFile::copy("C:/Users/ilknu/Documents/deneme/thread.txt", "C:/Users/ilknu/Documents/MyThread/new.txt");
    
        emit writingDone();
    
    
    }
    
    
    void MyThread::run()  //Reading file from txt with thread1
    {
    
    
        if (file.open(QIODevice::ReadOnly))
        {
            QTextStream in (&file);
            while (!in.atEnd())
            {
    
                QString line = in.readLine();
                QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
                for(const QString &entry : list)
                {
                    double num = entry.toDouble();
                    qDebug()<< "im running on worker thread " <<num;
                    queue.enqueue(num);
    
    
                } // for
            } // while
        } // if
    
        file.close();
    }
    

    main.cpp

    #include <QCoreApplication>
    #include "mythread.h"
    #include <QFile>
    #include <QDebug>
    #include <QThread>
    #include <mainwindow.h>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        MyThread mThread;
        mThread.start();
    
    
        qDebug() << "im running on gui thread " << a.thread()->currentThreadId();
        return a.exec();
    }
    
    mythread.h
    
    #ifndef MYTHREAD_H
    #define MYTHREAD_H
    #include <QtCore>
    #include <QMainWindow>
    #include <QObject>
    #include <QWidget>
    #include <QQueue>
    #include <QMutex>
    #include <QThread>
    class MyThread: public QThread
    {
        Q_OBJECT
    
    public:
        MyThread(QObject* parent =nullptr);
        ~MyThread();
        void run();
        //void writeData();
    
    signals:
        void writingDone();
    
    public slots:
        void writeData();
        //void run();
    
    
    private:
        QQueue<double> queue;
    };
    
    #endif // MYTHREAD_H
    

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QThread>
    #include "mythread.h"
    #include <QtWidgets/QMainWindow>
    #include <QMainWindow>
    #include <QQueue>
    
    QT_BEGIN_NAMESPACE
    namespace Ui {
    class MainWindow;
    }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = Q_NULLPTR);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
        MyThread* myThreadObject;
        QThread* myQThread;
    
    
    signals:
        void startWriting();
    
    public slots:
        void writingDoneByThread();
    
    
    };
    
    
    #endif // MAINWINDOW_H
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You did not implement the writingDoneByThread slot.

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

      D 1 Reply Last reply
      3
      • Jonas KvingeJ Offline
        Jonas KvingeJ Offline
        Jonas Kvinge
        wrote on last edited by
        #3

        @suslucoder said in error: undefined reference to &#x60;non-virtual thunk to MainWindow::~MainWindow()':

        MainWindow

        And the MainWindow destructor.

        1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          You did not implement the writingDoneByThread slot.

          D Offline
          D Offline
          deleted286
          wrote on last edited by deleted286
          #4

          @SGaist I fixed that problem. But my writing thread does not work

          jsulmJ SGaistS 2 Replies Last reply
          0
          • D deleted286

            @SGaist I fixed that problem. But my writing thread does not work

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @suslucoder You should be actually able to find out what the problem is checking the compiler error and your code. Please spend some time for that before asking in a forum.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • D deleted286

              @SGaist I fixed that problem. But my writing thread does not work

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @suslucoder said in error: undefined reference to &#x60;non-virtual thunk to MainWindow::~MainWindow()':

              @SGaist I fixed that problem. But my writing thread does not work

              This a problem unrelated to this topic. Since that part is working now, please mark it as solved. You already have other threads opened with regard to your threading issues.

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

              D 1 Reply Last reply
              2
              • SGaistS SGaist

                @suslucoder said in error: undefined reference to &#x60;non-virtual thunk to MainWindow::~MainWindow()':

                @SGaist I fixed that problem. But my writing thread does not work

                This a problem unrelated to this topic. Since that part is working now, please mark it as solved. You already have other threads opened with regard to your threading issues.

                D Offline
                D Offline
                deleted286
                wrote on last edited by
                #7

                @SGaist Okey, thank you

                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