QObject::connect: Cannot queue arguments of type 'Ui::Widget*'
товарищи. Прошу помощи. Задача: cчитать табличку из Excel и заполнить ею QTableWidget. Все работало, QTableWidget заполнялся, только интерфейс зависал. Я отправил задачу в поток, после чего стала вылазить ошибка
qt.core.qobject.connect: QObject::connect: Cannot queue arguments of type 'Ui::Widget*' (Make sure 'Ui::Widget*' is registered using qRegisterMetaType().)
Прикладываю код:
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QThread>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class ReadFromExcel : public QObject
{
Q_OBJECT
public:
explicit ReadFromExcel(QObject *parent = 0);
public slots:
void runRead(Ui::Widget *ui);
private:
// void readExcel();
};
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private slots:
void on_pushButton_clicked();
signals:
void startOperation(Ui::Widget *ui);
private:
Ui::Widget *ui;
ReadFromExcel *rfe;
QThread *thread;
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include "./ui_widget.h"
#include <QtGui>
#include <ActiveQt/qaxobject.h>
#include <ActiveQt/qaxbase.h>
#include <QTableWidget>
#include <QTableWidgetItem>
//Q_DECLARE_METATYPE(Ui::Widget*)
QString file("D:\\Programs\\123.xls");
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//qRegisterMetaType <Ui::Widget*> ("Ui::Widget*");
thread = new QThread(this);
connect(this, SIGNAL(destroyed()), thread, SLOT(quit()));
rfe = new ReadFromExcel();
connect(this,&Widget::startOperation,rfe,&ReadFromExcel::runRead);
rfe->moveToThread(thread);
thread->start();
}
Widget::~Widget()
{
delete ui;
}
ReadFromExcel::ReadFromExcel(QObject *parent) : QObject(parent)
{
}
void ReadFromExcel::runRead(Ui::Widget* ui)
{
QAxObject* excel = new QAxObject("Excel.Application", this);
QAxObject* workbooks = excel->querySubObject("Workbooks");
QAxObject* workbook = workbooks->querySubObject("Open(const QString&)", file);
excel->dynamicCall("SetVisible(bool)", false);
QAxObject* worksheet = workbook->querySubObject("Worksheets(int)", 1);
QAxObject* usedrange = worksheet->querySubObject("UsedRange");
QAxObject* rows = usedrange->querySubObject("Rows");
QAxObject* columns = usedrange->querySubObject("Columns");
int intRowStart = usedrange->property("Row").toInt() - 1;
int intColStart = usedrange->property("Columns").toInt();
int intRows = rows->property("Count").toInt();
int intCols = columns->property("Count").toInt();
qDebug()<<intRowStart;
qDebug()<<intColStart;
qDebug()<<intRows;
qDebug()<<intCols;
ui->table->setRowCount(intRowStart + intRows);
ui->table->setColumnCount(intColStart + intCols);
qDebug()<<ui->table->rowCount();
qDebug()<<ui->table->columnCount();
for (int row = 0; row < intRows; row++){
for (int col = 0; col < intCols; col++){
QAxObject* cell = worksheet->querySubObject("Cells(QVariant,QVariant)", row + 1, col + 1);
QVariant value = cell->dynamicCall("Value");
qDebug()<<row<<" "<<col<<" "<<value;
//delete cell;
QTableWidgetItem* item = new QTableWidgetItem(value.toString());
ui->table->setItem(row,col,item);
qDebug()<<row<<" "<<col<<" "<<item->text();
}
QCoreApplication::processEvents();
}
workbook->dynamicCall("Close()");
excel->dynamicCall("Quit()");
}
void Widget::on_pushButton_clicked()
{
//Будет вводиться путь к табилце Excel
emit startOperation(ui);
}
Попробовал сделать qRegisterMetaType() (см. закоментировано в коде widget.cpp), вылазит другая ошибка:
QAxBase::setControl: requested control Excel.Application could not be instantiated QAxBase::dynamicCallHelper: Object is not initialized, or initialization failed 06:00:42: Программа неожиданно завершилась.
Может проблема в том, что в методе runRead указано (Ui::Widget* ui)? Если так, то как иначе получить доступ к ui->table?
Заранее благодарен за помощь!