0

I am trying to create a progress bar for my class member function when it runs, but when I pass an array of strings and an array of bools into the QTConcurren::run function I get this error:

Error C2075 'QtConcurrent::VoidStoredMemberFunctionPointerCall4::arg1': array initialization requires a brace-enclosed initializer list.

My class is called CreateInputFiles, and the object of that class is called inpFileObj.

I tried adding & in front of the name of the array, but I got yet another error.

main.cpp

#include <iostream>
#include <iterator>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <atlstr.h>
#include <windows.h>
#include <QtWidgets/QApplication>
#include "UserInputClass.h"
int main(int argc, char*argv[]) {
 QApplication app(argc, argv);
 UserInputClass u;
 u.show();
 return app.exec();
}

CreateInputFiles.h

#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <vector>
#include <iterator>
#include <Windows.h>
#include <filesystem>
#include <fstream>
#include <sstream>
#include <boost/range/combine.hpp>
#include<set>
class CreateInputFiles
{
CreateInputFiles();
~CreateInputFiles();
public:
 void createInputFileFn(string arguments[],int numInpFiles, bool args[],int numFlags) {
  for( int count = 0; count < 5; count++ ) {
   sleep( 1 );
   std::cout << "Ping!" << std::endl;
  }
 }
};

UserInputClass.h

#include <QDialog>
#include <QMouseEvent>
#include "ui_UserInputClass.h"
#include "CreateInputFiles.h"
#include <QDir>
#include <QFileDialog>
#include <QWindow>
#include <iostream> 
#include <list> 
#include <iterator>
#include <string>
#include <QtConcurrent>
#include <QFutureWatcher>
using namespace std;
class Form : public QDialog
{
 Q_OBJECT
public slots:
 void on_pushButton_clicked();

public:
 UserInputClass(QWidget *parent = Q_NULLPTR);
~UserInputClass();

private:
 CreateInputFiles inpFileObj;
};

UserInputClass.cpp

#include <iostream>
#include "UserInputClass.h"  
#include <iterator>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <atlstr.h>
#include <windows.h>
Form::Form(QWidget *parent)
 : QDialog(parent)
{
 ui.setupUi(this);
}
void UserInputClass::on_pushButton_clicked() {
string inpArguments[3]; 
inpArguments[0]= oP;
inpArguments[1]=j17file;
inpArguments[2]=j19file;
int arrStrLength = (sizeof(inpArguments) / sizeof(*inpArguments));
bool flagArgs[2];
flagArgs[0]=true;
flagArgs[1]=true;
int arrLength = (sizeof(flagArgs) / sizeof(*flagArgs));
//this line below is causing the error
QFuture<void> future = QtConcurrent::run(&inpFileObj,&CreateInputFiles::createInputFileFn,inpArguments, arrStrLength,flagArgs, arrLength);
    this->FutureWatcher.setFuture(future);
}

UserInputClass.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QDialog" name="UserInputClass">
 <property name="geometry">
 <rect>
 <x>0</x>
 <y>0</y>
 <width>400</width>
 <height>300</height>
 </rect>
 </property>
 <property name="windowTitle">
 <string>Form</string>
 </property>
 <layout class="QVBoxLayout" name="verticalLayout">
 <item>
 <widget class="QPushButton" name="pushButton">
 <property name="text">
 <string>PushButton</string>
 </property>
 </widget>
 </item>
 </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

Error C2075 'QtConcurrent::VoidStoredMemberFunctionPointerCall4::arg1': array initialization requires a brace-enclosed initializer list

BDD
  • 25
  • 1
  • 6
  • You use [ ... ] for initialization of flagArgs when you need to use { ... } instead. The error message seems pretty clear btw. – nada Aug 13 '19 at 17:06
  • I just wrote that for that sake of brevity. I initialize my array with: string inputArguments[5]; Then I fill in the spaces of the array one by one. Example: inputArguments[0]="red"; inputArguments[1]="blue" etc – BDD Aug 13 '19 at 17:14
  • I will change my code here to reflect what is in my actual program. – BDD Aug 13 '19 at 17:18
  • Please post a [mcve]. – n. m. could be an AI Aug 13 '19 at 17:43
  • Sorry Im very new to posting on StackOverflow. Let me know if I did it right this time. – BDD Aug 13 '19 at 18:20
  • Do you feed your compiler files without a single `#include` directive? – n. m. could be an AI Aug 13 '19 at 19:52
  • I do use include at the top of my files. Also I am using Visual Studio 2017 so I changed the Additional include directories tab to include QTConcurrent. I thought that since this was a minimal reproducible example I didn't need the includes. I didn't feel like includes aided in understanding my code. Correct me if I'm wrong. – BDD Aug 13 '19 at 20:08
  • So you are not showing us the exact same thing you are showing to your compiler. This doesn't work. To reproduce your results I need to correctly guess which include directives you are using. This is additional work for me that could have been avoided. I charge $50 per standard header and $150 per third party one. – n. m. could be an AI Aug 14 '19 at 18:53
  • That's fair. I just added the includes. – BDD Aug 14 '19 at 19:16

1 Answers1

0

Just found a Solution! Never use C-Style Arrays in QtConcurrent::run. Use C++ std::array instead!

BDD
  • 25
  • 1
  • 6