[SOLVED] error LNK2019 with QAxObject and QAxBase
-
Hello! I try to make some "read-from-excel-write-to-DB" module.
I don't understand why I got such errors@ error LNK2019: unresolved external symbol "public: __thiscall QAxObject::QAxObject(class QString const &,class QObject *)" (??0QAxObject@@QAE@ABVQString@@PAVQObject@@@Z) referenced in function "public: bool __thiscall importdb_module::initExcel(class QAxObject * &)" (?initExcel@importdb_module@@QAE_NAAPAVQAxObject@@@Z)@
Could you help me to fix it please?
Well, thats how all thing there looks at this momentimportdb_module.h
@#ifndef IMPORTDB_MODULE_H
#define IMPORTDB_MODULE_H#include <QtGui/QMainWindow>
#include <QAxObject>
#include "ui_importdb_module.h"class importdb_module : public QMainWindow
{
Q_OBJECTpublic:
importdb_module(QWidget *parent = 0, Qt::WFlags flags = 0);
~importdb_module();void testExlOp(QString &path);
private:
Ui::importdb_moduleClass ui;bool initExcel(QAxObject* &excelApp); //for initialization
bool readExcelFile(QAxObject* excel, QString& file_path, QString& selected_list); //for read what we need to
void getTableHeaders(QAxObject* _worksheet, QAxObject* _excel); //get colunm headrespublic slots:
void on_getExcelPath_clicked();};
#endif // IMPORTDB_MODULE_H@
importdb_module.cpp
@#include <QtGui>
#include "importdb_module.h"importdb_module::importdb_module(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
}importdb_module::~importdb_module()
{}
//for initialization
bool importdb_module::initExcel(QAxObject* &excelApp){
bool initialized;
//try to set pointer to excel
try{
excelApp = new QAxObject("Excel.Application");
if (excelApp){
initialized = true;}
else{
QMessageBox::information(0, "", "Excel/Office not installed");
initialized = false; //if we can't use excel
}}
//catch if it already opened
catch(...){
//idk how
}
return initialized;
}//for read what we need to
bool importdb_module::readExcelFile(QAxObject* excel, QString& file_path, QString& selected_list){
bool read_done;//if initialization succesuful we gonna read some stuff from file
if(initExcel(excel)){//sort of init
//get pointer to booklist then open file
QAxObject* workbooks = excel->querySubObject("WorkBooks");
workbooks->dynamicCall("Open (const QString&)", file_path);
//get pointer to woorkbook in active excel
QAxObject* workbook = excel->querySubObject("ActiveWorkBook");
//represents all the worksheets in the specified workbook
QAxObject* worksheets = workbook->querySubObject("WorkSheets");
//select sheet by name
QAxObject* worksheet_selected = workbook->querySubObject("Worksheets(int)", 1);//( "WorkSheets(const QVariant&)", selected_list);
//sort of init//read headers only
getTableHeaders(worksheet_selected, excel);
read_done = true;//cleaning the mess
worksheet_selected->clear(); //delete elements in such order!
delete worksheet_selected;
worksheet_selected = NULL;workbook->clear();
delete workbook;
workbook = NULL;workbooks->dynamicCall( "Close" );
workbooks->clear();
delete workbooks;
workbooks = NULL;
}
else //if excel not init'zed
{
QMessageBox::information(0, "", "Fail");
read_done = false;
}return read_done;
}
void importdb_module::testExlOp(QString &_path){
QAxObject* excel;QString path = _path;//gonna use GUI choose
QString list = QString("list1");if(initExcel(excel)){
if (readExcelFile(excel, path, list)){
//
}else{
//error output
}
}excel->dynamicCall("Quit");
delete excel;
}void getTableHeaders(QAxObject* _worksheet, QAxObject* _excel){
QStringList headers_list;QAxObject* usedrange = _worksheet->querySubObject("UsedRange"); //select fulled range
//getting rows, cols of that range
QAxObject* rows = usedrange->querySubObject("Rows");
QAxObject* columns = usedrange->querySubObject("Columns");
int intRowStart = usedrange->property("Row").toInt();
int intColStart = usedrange->property("Column").toInt();
int intCols = columns->property("Count").toInt();
//string below not necessary right now
//int intRows = rows->property("Count").toInt();//thats how we get to table cells
QAxObject* cell;
QVariant cellValue;for (int j = intColStart; j < intColStart + intCols; j++)//(int i = intRowStart; i < intRowStart + intRows; i++)
{
//in this case we get only column headers
cell = _excel->querySubObject("Cells(Int, Int)", intRowStart, j);
cellValue = cell->dynamicCall("value");
headers_list<<cellValue.toString();
}
//output in debug console
for (int i = 0; i < headers_list.size(); ++i){
qDebug()<<headers_list.at(i);
}delete rows;
delete columns;
delete cell;
}
//button 'Import' pressed (o. name getExcelPath)
void importdb_module::on_getExcelPath_clicked(){QString path;
//file browse window
path = QFileDialog::getOpenFileName(
this,
"Choose a file to open",
QString::null,
QString::null);
testExlOp(path);}@
main.cpp
@#include "importdb_module.h"
#include <QtGui/QApplication>
#include <QApplication>
#include <QtGui>
#include <QtSql>
#include <QAxWidget>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
importdb_module w;
w.show();
return a.exec();
}@ -
Hi and welcome to devnet,
Did you add
@CONFIG += qaxcontainer@
to your pro file ?
-
[quote author="SGaist" date="1382471432"]Hi and welcome to devnet,
Did you add
@CONFIG += qaxcontainer@
to your pro file ?[/quote]
Hello! I use VS 2008, so, there in linker->input->additional dependencies I added this
@QAxContainerd.lib@It kinda helped! There were 4 errors befr, but after rebuild now only one left:
@error LNK2019: unresolved external symbol "private: void __thiscall importdb_module::getTableHeaders(class QAxObject *,class QAxObject *)" (?getTableHeaders@importdb_module@@AAEXPAVQAxObject@@0@Z) referenced in function "private: bool __thiscall importdb_module::readExcelFile(class QAxObject *,class QString &,class QString &)" (?readExcelFile@importdb_module@@AAE_NPAVQAxObject@@AAVQString@@1@Z) importdb_module.obj importdb_module@
Seems like it's because QAxObject, but I already included QAxContainer. I got no idea why it appears
-
Oh, sorry, I fixed it! I forgot to wrote
@importdb_module::@ before @getTableHeaders@ function!
Thank you, SGaist!
-
You're welcome !
Since you have it working now, please update the thread title prepending solved so other forum users may know a solution has been found :)