I am trying to run a QtConcurrent::run from a QAbstractTableModel but run it as a non static method.
Here is my header file:
#ifndef DATA_INFO_HPP
#define DATA_INFO_HPP
#include <QAbstractTableModel>
#include <QObject>
#include <QFutureWatcher>
#include <QtConcurrent/QtConcurrent>
struct DATA
{
quint32 pages;
quint32 chapers;
quint32 books;
};
inline QDataStream &operator<<(QDataStream &readstream, const DATA &m_data)
{
return readstream << m_data.pages << m_data.chapers << m_data.books;
}
inline QDataStream &operator>>(QDataStream &writestream, DATA &m_data)
{
return writestream >> m_data.pages >> m_data.chapers >> m_data.books;
}
class Data_Info : public QAbstractTableModel
{
Q_OBJECT
using rowData = QVector<DATA>;
QFutureWatcher<rowData>* m_watcher;
rowData m_rows;
public:
Data_Info(QByteArray Data, QObject* parent= nullptr);
rowData retrieveData(QByteArray Data);
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
const QVector<DATA> &getData() const;
public slots:
void updateData();
private:
};
#endif // DATA_INFO_HPP
Inside my .cpp file i try to call it like this:
#include "data_info.hpp"
Data_Info::Data_Info(QByteArray Data, QObject *parent):QAbstractTableModel(parent)
{
m_watcher = new QFutureWatcher<rowData>(this);
connect(m_watcher, &QFutureWatcher<rowData>::finished,this, &Data_Info::updateData);
QFuture<rowData> future = QtConcurrent::run(&Data_Info::retrieveData, Data);
m_watcher->setFuture(future);
}
Data_Info::rowData Data_Info::retrieveData(QByteArray Data)
{
quint32 addRowCounter = 0;
quint32 addRowCounterLoop = 0;
rowData list;
DATA m_data;
QDataStream readstream(Data);
readstream.setByteOrder(QDataStream::LittleEndian);
readstream >> addRowCounter;
while(!readstream.atEnd())
{
readstream >> m_data;
list.append( m_data );
++addRowCounterLoop;
if (addRowCounter == addRowCounterLoop)
{
break;
}
}
return list;
}
void Data_Info::updateData()
{
beginResetModel();
m_rows = m_watcher->future().result();
endResetModel();
}
my issue seems to lie that QtConcurrent::run only takes a static method?
QFuture<rowData> future = QtConcurrent::run(&Data_Info::retrieveData, Data);
How would i go about fixing this error? Just want to run a thread inside this object?