PDA

View Full Version : QProcess start signal: invalid parameter passed to C runtime function



pawlow.pawel
4th January 2012, 11:28
Hi,

i have a class with a varibale:

QProcess proc;

in the constructor of the class I connect signls of proc:

QObject::connect(&(this->proc),SIGNAL(started()),this,SLOT(smootherStarted( )));
QObject::connect(&(this->proc),SIGNAL(finished(int, QProcess::ExitStatus)),this,SLOT(smootherFinished( int, QProcess::ExitStatus)));
QObject::connect(&(this->proc),SIGNAL(error(QProcess::ProcessError)),this,S LOT(processError(QProcess::ProcessError)));
QObject::connect(&(this->proc),SIGNAL(readyRead()),this,SLOT(readyToRead()) );

Everything works fine until the "started()" signals is not connected (commented out). If I use that signal I get the following error in debug window:

ASSERT: "d" in file c:\QtSDK\Desktop\Qt\4.7.4\mingw\include/QtCore/qscopedpointer.h, line 112
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
ASSERT: "d" in file c:\QtSDK\Desktop\Qt\4.7.4\mingw\include/QtCore/qscopedpointer.h, line 112
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.

Moreover, two dialog windows from Microsoft Visual C++ Runtime Library are displayed, both having the same (rather meaningless) information:
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

I use latest Qt SDK, I mean I updated all the stuff with built-in tool to the latest available version. I work under Win7 x64 if it matters.

I have no idea why it happens and where to look for. What's surprising the whole code worked for some time without any problems regarding QProcess.
Does anyone has any clues/ideas?

Thank you for your answers

mentalmushroom
4th January 2012, 14:03
It is difficult to find the bug without the code. Those few lines don't tell much.

pawlow.pawel
4th January 2012, 16:07
This is the code of the relevant class.
Header file:



class Smoother : public QObject {

Q_OBJECT

private:
///internal use vars
SmootherSettings settings;
QString fortranSmoother;
unsigned short int columns;
unsigned int rows;
QTemporaryFile* tmpInputFile;
QTemporaryFile* tmpOutputFile2;
QString originalOutputFile2;

QProcess proc;

enum SmoothingStep { INPUT_FILE, OUTPUT_FILE_1, OUTPUT_FILE_2, SAMPLES_AMOUNT, COLUMNS_AMOUNT,
SMOOTHED_COLUMN, POINTS_NUMBER_IN_SINGLE_STEP, APPROX_POLYNOM_ORDER,
DERIVATIVE_ORDER, SMOOTHINGS_NUMBER, END };

enum SmoothingStep curr_step;


//data returned from SMOOTHER


//internal use functions
void interpretSmootherProcAnswer(const QString& answer);
void askSmootherProc();
void preprocessInputFile();

QString convertInputXLStoDAT();
void convertOutputDATtoXLS();

public:
Smoother(const QString& arg_fortranSmoother, const struct SmootherSettings& arg_data);
~Smoother();

void run();

public slots:
void smootherStarted();
void smootherFinished(int exitCode, QProcess::ExitStatus exitStatus);
void readyToRead();
void processError(QProcess::ProcessError error);

signals:
void finished(int exitCode, QProcess::ExitStatus exitStatus);
void started();
void progress(unsigned short percent, QString currentActionDescription);
void error(Exception e);
void strSent(const QString& str);
void strReceived(const QString& str);
};


Source file (functions that are not listed here, do not make any use of proc):


Smoother::Smoother(const QString& arg_fortranSmoother, const SmootherSettings &arg_data)
: settings(arg_data), fortranSmoother(arg_fortranSmoother), columns(0), rows(0), tmpInputFile(0), tmpOutputFile2(0), curr_step(INPUT_FILE) {

QObject::connect(&(this->proc),SIGNAL(started()),this,SLOT(smootherStarted( )));
QObject::connect(&(this->proc),SIGNAL(finished(int, QProcess::ExitStatus)),this,SLOT(smootherFinished( int, QProcess::ExitStatus)));
QObject::connect(&(this->proc),SIGNAL(error(QProcess::ProcessError)),this,S LOT(processError(QProcess::ProcessError)));
QObject::connect(&(this->proc),SIGNAL(readyRead()),this,SLOT(readyToRead()) );

}

Smoother::~Smoother() {
QObject::disconnect(&(this->proc));
this->proc.close();
if(tmpInputFile) {
tmpInputFile->close();
tmpInputFile->remove();
delete tmpInputFile;
}
if(tmpOutputFile2){
tmpOutputFile2->close();
tmpOutputFile2->remove();
delete tmpOutputFile2;
}
}

void Smoother::run() {
//input file preprocessing
preprocessInputFile();
if(columns == 0 || rows == 0) {
emit strSent("Process cannot be started. Invalid input file");
return;
}

this->originalOutputFile2 = settings.outputFile2;
QFileInfo fi(settings.outputFile2);
QString ext = fi.suffix();
if(ext == "xls") {
settings.outputFile2 = QDir::tempPath() + QDir::separator() + "pwsmoother_tmp.out.dat";
}

QString cmd = QString("\"%1\"").arg(( this->fortranSmoother )).toStdString().c_str();
try {
proc.start(cmd, QIODevice::ReadWrite | QIODevice::Text);
} catch(...) {
emit Exception(102, trUtf8("BÅ‚ad uruchamiania podprocesu: %1").arg(cmd));
}

emit started();
emit strSent(cmd);
}

void Smoother::smootherStarted() {
emit progress(1,"Just started...");
}

void Smoother::smootherFinished(int exitCode, QProcess::ExitStatus exitStatus) {
if(tmpInputFile) {
delete tmpInputFile;
tmpInputFile = 0;
}
emit progress(100,"Finished");
//output file postprocessing possible here
if( originalOutputFile2 != settings.outputFile2 ) {
convertOutputDATtoXLS();
}
emit finished(exitCode, exitStatus);
}

void Smoother::readyToRead() {
QString readStr;
QByteArray da;
da = this->proc.readAll();
readStr = QString(da);
emit strReceived(readStr);

interpretSmootherProcAnswer(readStr);
askSmootherProc();
}

void Smoother::processError(QProcess::ProcessError error) {
Exception e(error);
emit this->error(e);
}

void Smoother::interpretSmootherProcAnswer(const QString &answer) {
switch(curr_step) {
default:
break;
}
}

void Smoother::askSmootherProc() {
switch(curr_step) {
case INPUT_FILE:
emit progress(5, "Input file");
proc.write(QString("%1\n").arg(settings.inputFile).toStdString().c_str());
emit strSent(settings.inputFile);
curr_step = OUTPUT_FILE_1;
break;
case OUTPUT_FILE_1:
emit progress(10, "First output file");
proc.write(QString("%1\n").arg(settings.outputFile1).toStdString().c_str()) ;
emit strSent(settings.outputFile1);
curr_step = OUTPUT_FILE_2;
break;
case OUTPUT_FILE_2:
emit progress(15, "Second output file");
proc.write(QString("%1\n").arg(settings.outputFile2).toStdString().c_str()) ;
emit strSent(settings.outputFile2);
curr_step = SAMPLES_AMOUNT;
break;
case SAMPLES_AMOUNT:
emit progress(20, "Samples amount");
proc.write(QString("%1\n").arg(rows).toStdString().c_str());
emit strSent(QString::number(rows));
curr_step = COLUMNS_AMOUNT;
break;
case COLUMNS_AMOUNT:
emit progress(25, "Columns amount");
proc.write(QString("%1\n").arg(columns).toStdString().c_str());
emit strSent(QString::number(columns));
curr_step = SMOOTHED_COLUMN;
break;
case SMOOTHED_COLUMN:
emit progress(30, "Smoothed column");
proc.write(QString("%1\n").arg(settings.smoothedColumn).toStdString().c_str ());
emit strSent(QString::number(settings.smoothedColumn));
curr_step = POINTS_NUMBER_IN_SINGLE_STEP;
break;
case POINTS_NUMBER_IN_SINGLE_STEP:
emit progress(35, "Points number in signle smoothing step");
proc.write(QString("%1\n").arg(settings.pointsNumberInSingleStep).toStdStri ng().c_str());
emit strSent(QString::number(settings.pointsNumberInSin gleStep));
curr_step = APPROX_POLYNOM_ORDER;
break;
case APPROX_POLYNOM_ORDER:
emit progress(40, "Order of approx. polynom");
proc.write(QString("%1\n").arg(settings.approxPolynomOrder).toStdString().c _str());
emit strSent(QString::number(settings.approxPolynomOrde r));
curr_step = DERIVATIVE_ORDER;
break;
case DERIVATIVE_ORDER:
emit progress(45, "Derivative order");
proc.write(QString("%1\n").arg(settings.derivativeOrder).toStdString().c_st r());
emit strSent(QString::number(settings.derivativeOrder)) ;
curr_step = SMOOTHINGS_NUMBER;
break;
case SMOOTHINGS_NUMBER:
emit progress(50, "Smoothings number");
proc.write(QString("%1\n").arg(settings.smoothingsNumber).toStdString().c_s tr());
emit strSent(QString::number(settings.smoothingsNumber) );
curr_step = END;
break;
case END:
emit progress(100,"Done");
break;
default:
break;
}
}


In debug mode the program crashed, after F10 on emit in Smoother::smootherStarted();

amleto
4th January 2012, 16:50
ahh, misunderstood. re-reading..

-----

what do you connect progress signal to?

have you tried,


QString str("blah");
emit progress(1, str);
?

pawlow.pawel
4th January 2012, 22:43
There was a problem in a function that was called as result of that emit. However, it happened only in specific conditions what was unfortunatelly hard to track down. Debugger did not provide any straightforward useful information. Thank you for your hints