error: undefined reference to `non-virtual thunk to MainWindow::~MainWindow()'
-
I could not solve these problems. What is my mistake?
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
-
Hi,
You did not implement the writingDoneByThread slot.
-
@suslucoder said in error: undefined reference to `non-virtual thunk to MainWindow::~MainWindow()':
MainWindow
And the MainWindow destructor.
-
@SGaist I fixed that problem. But my writing thread does not work
-
@SGaist I fixed that problem. But my writing thread does not work
@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.
-
@SGaist I fixed that problem. But my writing thread does not work
@suslucoder said in error: undefined reference to `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.
-
@suslucoder said in error: undefined reference to `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.
@SGaist Okey, thank you