Results 1 to 5 of 5

Thread: QProcess start signal: invalid parameter passed to C runtime function

  1. #1
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QProcess start signal: invalid parameter passed to C runtime function

    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, SLOT(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

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QProcess start signal: invalid parameter passed to C runtime function

    It is difficult to find the bug without the code. Those few lines don't tell much.

  3. #3
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess start signal: invalid parameter passed to C runtime function

    This is the code of the relevant class.
    Header file:

    Qt Code:
    1. class Smoother : public QObject {
    2.  
    3. Q_OBJECT
    4.  
    5. private:
    6. ///internal use vars
    7. SmootherSettings settings;
    8. QString fortranSmoother;
    9. unsigned short int columns;
    10. unsigned int rows;
    11. QTemporaryFile* tmpInputFile;
    12. QTemporaryFile* tmpOutputFile2;
    13. QString originalOutputFile2;
    14.  
    15. QProcess proc;
    16.  
    17. enum SmoothingStep { INPUT_FILE, OUTPUT_FILE_1, OUTPUT_FILE_2, SAMPLES_AMOUNT, COLUMNS_AMOUNT,
    18. SMOOTHED_COLUMN, POINTS_NUMBER_IN_SINGLE_STEP, APPROX_POLYNOM_ORDER,
    19. DERIVATIVE_ORDER, SMOOTHINGS_NUMBER, END };
    20.  
    21. enum SmoothingStep curr_step;
    22.  
    23.  
    24. //data returned from SMOOTHER
    25.  
    26.  
    27. //internal use functions
    28. void interpretSmootherProcAnswer(const QString& answer);
    29. void askSmootherProc();
    30. void preprocessInputFile();
    31.  
    32. QString convertInputXLStoDAT();
    33. void convertOutputDATtoXLS();
    34.  
    35. public:
    36. Smoother(const QString& arg_fortranSmoother, const struct SmootherSettings& arg_data);
    37. ~Smoother();
    38.  
    39. void run();
    40.  
    41. public slots:
    42. void smootherStarted();
    43. void smootherFinished(int exitCode, QProcess::ExitStatus exitStatus);
    44. void readyToRead();
    45. void processError(QProcess::ProcessError error);
    46.  
    47. signals:
    48. void finished(int exitCode, QProcess::ExitStatus exitStatus);
    49. void started();
    50. void progress(unsigned short percent, QString currentActionDescription);
    51. void error(Exception e);
    52. void strSent(const QString& str);
    53. void strReceived(const QString& str);
    54. };
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. Smoother::Smoother(const QString& arg_fortranSmoother, const SmootherSettings &arg_data)
    2. : settings(arg_data), fortranSmoother(arg_fortranSmoother), columns(0), rows(0), tmpInputFile(0), tmpOutputFile2(0), curr_step(INPUT_FILE) {
    3.  
    4. QObject::connect(&(this->proc),SIGNAL(started()),this,SLOT(smootherStarted()));
    5. QObject::connect(&(this->proc),SIGNAL(finished(int, QProcess::ExitStatus)),this,SLOT(smootherFinished(int, QProcess::ExitStatus)));
    6. QObject::connect(&(this->proc),SIGNAL(error(QProcess::ProcessError)),this,SLOT(processError(QProcess::ProcessError)));
    7. QObject::connect(&(this->proc),SIGNAL(readyRead()),this,SLOT(readyToRead()));
    8.  
    9. }
    10.  
    11. Smoother::~Smoother() {
    12. QObject::disconnect(&(this->proc));
    13. this->proc.close();
    14. if(tmpInputFile) {
    15. tmpInputFile->close();
    16. tmpInputFile->remove();
    17. delete tmpInputFile;
    18. }
    19. if(tmpOutputFile2){
    20. tmpOutputFile2->close();
    21. tmpOutputFile2->remove();
    22. delete tmpOutputFile2;
    23. }
    24. }
    25.  
    26. void Smoother::run() {
    27. //input file preprocessing
    28. preprocessInputFile();
    29. if(columns == 0 || rows == 0) {
    30. emit strSent("Process cannot be started. Invalid input file");
    31. return;
    32. }
    33.  
    34. this->originalOutputFile2 = settings.outputFile2;
    35. QFileInfo fi(settings.outputFile2);
    36. QString ext = fi.suffix();
    37. if(ext == "xls") {
    38. settings.outputFile2 = QDir::tempPath() + QDir::separator() + "pwsmoother_tmp.out.dat";
    39. }
    40.  
    41. QString cmd = QString("\"%1\"").arg(( this->fortranSmoother )).toStdString().c_str();
    42. try {
    43. proc.start(cmd, QIODevice::ReadWrite | QIODevice::Text);
    44. } catch(...) {
    45. emit Exception(102, trUtf8("BÅ‚ad uruchamiania podprocesu: %1").arg(cmd));
    46. }
    47.  
    48. emit started();
    49. emit strSent(cmd);
    50. }
    51.  
    52. void Smoother::smootherStarted() {
    53. emit progress(1,"Just started...");
    54. }
    55.  
    56. void Smoother::smootherFinished(int exitCode, QProcess::ExitStatus exitStatus) {
    57. if(tmpInputFile) {
    58. delete tmpInputFile;
    59. tmpInputFile = 0;
    60. }
    61. emit progress(100,"Finished");
    62. //output file postprocessing possible here
    63. if( originalOutputFile2 != settings.outputFile2 ) {
    64. convertOutputDATtoXLS();
    65. }
    66. emit finished(exitCode, exitStatus);
    67. }
    68.  
    69. void Smoother::readyToRead() {
    70. QString readStr;
    71. da = this->proc.readAll();
    72. readStr = QString(da);
    73. emit strReceived(readStr);
    74.  
    75. interpretSmootherProcAnswer(readStr);
    76. askSmootherProc();
    77. }
    78.  
    79. void Smoother::processError(QProcess::ProcessError error) {
    80. Exception e(error);
    81. emit this->error(e);
    82. }
    83.  
    84. void Smoother::interpretSmootherProcAnswer(const QString &answer) {
    85. switch(curr_step) {
    86. default:
    87. break;
    88. }
    89. }
    90.  
    91. void Smoother::askSmootherProc() {
    92. switch(curr_step) {
    93. case INPUT_FILE:
    94. emit progress(5, "Input file");
    95. proc.write(QString("%1\n").arg(settings.inputFile).toStdString().c_str());
    96. emit strSent(settings.inputFile);
    97. curr_step = OUTPUT_FILE_1;
    98. break;
    99. case OUTPUT_FILE_1:
    100. emit progress(10, "First output file");
    101. proc.write(QString("%1\n").arg(settings.outputFile1).toStdString().c_str());
    102. emit strSent(settings.outputFile1);
    103. curr_step = OUTPUT_FILE_2;
    104. break;
    105. case OUTPUT_FILE_2:
    106. emit progress(15, "Second output file");
    107. proc.write(QString("%1\n").arg(settings.outputFile2).toStdString().c_str());
    108. emit strSent(settings.outputFile2);
    109. curr_step = SAMPLES_AMOUNT;
    110. break;
    111. case SAMPLES_AMOUNT:
    112. emit progress(20, "Samples amount");
    113. proc.write(QString("%1\n").arg(rows).toStdString().c_str());
    114. emit strSent(QString::number(rows));
    115. curr_step = COLUMNS_AMOUNT;
    116. break;
    117. case COLUMNS_AMOUNT:
    118. emit progress(25, "Columns amount");
    119. proc.write(QString("%1\n").arg(columns).toStdString().c_str());
    120. emit strSent(QString::number(columns));
    121. curr_step = SMOOTHED_COLUMN;
    122. break;
    123. case SMOOTHED_COLUMN:
    124. emit progress(30, "Smoothed column");
    125. proc.write(QString("%1\n").arg(settings.smoothedColumn).toStdString().c_str());
    126. emit strSent(QString::number(settings.smoothedColumn));
    127. curr_step = POINTS_NUMBER_IN_SINGLE_STEP;
    128. break;
    129. case POINTS_NUMBER_IN_SINGLE_STEP:
    130. emit progress(35, "Points number in signle smoothing step");
    131. proc.write(QString("%1\n").arg(settings.pointsNumberInSingleStep).toStdString().c_str());
    132. emit strSent(QString::number(settings.pointsNumberInSingleStep));
    133. curr_step = APPROX_POLYNOM_ORDER;
    134. break;
    135. case APPROX_POLYNOM_ORDER:
    136. emit progress(40, "Order of approx. polynom");
    137. proc.write(QString("%1\n").arg(settings.approxPolynomOrder).toStdString().c_str());
    138. emit strSent(QString::number(settings.approxPolynomOrder));
    139. curr_step = DERIVATIVE_ORDER;
    140. break;
    141. case DERIVATIVE_ORDER:
    142. emit progress(45, "Derivative order");
    143. proc.write(QString("%1\n").arg(settings.derivativeOrder).toStdString().c_str());
    144. emit strSent(QString::number(settings.derivativeOrder));
    145. curr_step = SMOOTHINGS_NUMBER;
    146. break;
    147. case SMOOTHINGS_NUMBER:
    148. emit progress(50, "Smoothings number");
    149. proc.write(QString("%1\n").arg(settings.smoothingsNumber).toStdString().c_str());
    150. emit strSent(QString::number(settings.smoothingsNumber));
    151. curr_step = END;
    152. break;
    153. case END:
    154. emit progress(100,"Done");
    155. break;
    156. default:
    157. break;
    158. }
    159. }
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess start signal: invalid parameter passed to C runtime function

    ahh, misunderstood. re-reading..

    -----

    what do you connect progress signal to?

    have you tried,
    Qt Code:
    1. QString str("blah");
    2. emit progress(1, str);
    To copy to clipboard, switch view to plain text mode 
    ?
    Last edited by amleto; 4th January 2012 at 17:02.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default [SOLVED] Re: QProcess start signal: invalid parameter passed to C runtime function

    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

Similar Threads

  1. QProcess::pid() gives invalid data
    By shaolin in forum Qt Programming
    Replies: 7
    Last Post: 27th July 2011, 13:31
  2. Replies: 1
    Last Post: 1st March 2011, 21:01
  3. Replies: 4
    Last Post: 20th January 2011, 01:03
  4. Replies: 0
    Last Post: 24th October 2010, 19:09
  5. Replies: 1
    Last Post: 25th September 2010, 08:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.