Hello
I have a small example:
main.cpp
#include <QtCore/QCoreApplication>
#include "process.h"
int main(int argc, char *argv[])
{
Process *proc = new Process;
proc->startProcess();
return a.exec();
}
#include <QtCore/QCoreApplication>
#include "process.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Process *proc = new Process;
proc->startProcess();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
process.h
#ifndef PROCESS_H
#define PROCESS_H
#include <QProcess>
{
public:
Process();
void startProcess();
};
#endif // PROCESS_H
#ifndef PROCESS_H
#define PROCESS_H
#include <QProcess>
class Process : public QProcess
{
public:
Process();
void startProcess();
};
#endif // PROCESS_H
To copy to clipboard, switch view to plain text mode
process.cpp
#include "process.h"
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#ifdef Q_WS_WIN
#include <windows.h>
#endif
Process::Process()
{
}
void Process::startProcess()
{
#ifdef Q_WS_WIN
qDebug() << "Bin dran!";
fileName
= QDir::tempPath() + "/" + fileName;
this
->start
(QString("rundll32 url.dll,FileProtocolHandler \"%1\"").
arg( fileInfo.
absoluteFilePath()));
struct _PROCESS_INFORMATION *procInfo = this->pid();
qDebug() << "PID: " << procInfo->dwProcessId;
#endif
#ifndef Q_WS_WIN
#endif
}
#include "process.h"
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#ifdef Q_WS_WIN
#include <windows.h>
#endif
Process::Process()
{
}
void Process::startProcess()
{
#ifdef Q_WS_WIN
qDebug() << "Bin dran!";
QString fileName = "69874.ods";
fileName = QDir::tempPath() + "/" + fileName;
QFileInfo fileInfo(fileName);
this->start(QString("rundll32 url.dll,FileProtocolHandler \"%1\"").arg( fileInfo.absoluteFilePath()));
struct _PROCESS_INFORMATION *procInfo = this->pid();
qDebug() << "PID: " << procInfo->dwProcessId;
#endif
#ifndef Q_WS_WIN
#endif
}
To copy to clipboard, switch view to plain text mode
i want to open a document (works fine) and get the process for (in my case) for soffice/excel. But qt returned another pid (i think its the qprocess pid and not soffice).
We have a client-server architecture and i want to write back the file to the server if the editor is closed.
Is there a way to get the PID from the childprocess?
proc->state() returned always is runned.
Bookmarks