I can open the XLSX Excel format and read all data but only if the code for it is part of the constructor of the QMainWindow. For first tests to read the Excel it was fine. But when I move the algorithm to separate function to call it over the button press method it fail with popup error "Operating system is not configured to run this application".
Using Windows 10 / Qt 5.15.2 / MinGW
QMainWindow constructor:
t_ps_bps_grad2::t_ps_bps_grad2(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::t_ps_bps_grad2)
/* ************************************************************************** */
{
ui->setupUi(this);
db = QSqlDatabase::addDatabase("QODBC", "xlsx_connection");
// Working fine if function called from here: loadExcel();
}
function to load Excel:
void t_ps_bps_grad2::loadExcel()
/* ************************************************************************** */
{
QString pathToExcel = "C:\data.xlsx";
QString excelDriver = "DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + pathToExcel;
db.setDatabaseName(excelDriver);
if (db.open()) {
QSqlQuery *query = new QSqlQuery(db);
if (query->exec("select * from [Data$A1:B20000]")) {
while (query->next()) {
double double_p = query->value(0).toDouble();
// ...
}
}
}
}
void t_ps_bps_grad2::on_pushButton_clicked()
/* ************************************************************************** */
{
loadExcel(); // Not working from here !
}
Am I missing something?