How can i run a C# program from Qt C++ program?

123 views Asked by At

I have a program written in C# (.net framework 4.0) and i have a main program written in Qt C++, i need to run this program (C# program) from my main program, the problem is if i use QProcess to run it, nothing happens, i used waitForStarted and waitForFinished members functions of Qprocess but already timeout.

I tried Qprocess (start()), system(). Here is what i tried:

QProcess p;
p.start(qApp->applicationDirPath()+"/control.exe",{"0000"},QIODevice::ReadWrite);
p.waitForFinished();

QFile fff(qApp->applicationDirPath()+"/control.csv");
if(!fff.exists())

{
   /*Error control.csv not exists*/
}

control.exe extracts data from a datagridView and store it in control.csv file, but the csv file is not created while control.exe works perfectly when i run it from windows console. How can i run it from Qt C++ program?

PS: my C# program is a console application.

Thank for helping me.

1

There are 1 answers

0
Yanis600 On BEST ANSWER

After effort and perseverance, I managed to find the problem. This line had to be changed

File.WriteAllText("control.csv", string.Join("\n", rows));

By this one

File.WriteAllText(System.AppDomain.CurrentDomain.BaseDirectory+"control.csv", string.Join("\n", rows));

I already run it using QProcess object in Qt.

Indeed, I must specify the whole path using System.AppDomain.CurrentDomain.BaseDirectory where to store control.csv file, I thought it will be created near the C# program.

I noticed one think, the program is extremly slow to find the automationElement object, it takes more than 20 seconds.