简体   繁体   中英

Qt: Cannot queue arguments of type 'QProcess::ProcessError' - QProcess::ProcessError(FailedToStart)

I am trying to pass a serialized image to a process I started in my Qt program. However when doing so I get this error message:

QObject::connect: Cannot queue arguments of type 'QProcess::ProcessError'
(Make sure 'QProcess::ProcessError' is registered using qRegisterMetaType().)

The image I am trying to pass is a cv::Mat which I converted to a QImage which I afterwards converted to a QString.

Could someone tell me what I am doing incorrectly when streaming my parameters to the variable params? My current guess is that the issue lies in the serialized form of the image ie it contains many double quotes which is why when inserting the value of matQStr in the line below (to stream it to params), there is a misinterpretation

Everything else works perfectly fine, it is just now when trying to pass an image that something goes wrong.

In case you may need this information, the process I am starting is a python function using openCV taking 1 parameter, ie the image I am trying to pass. Serializing the image to pass it to the function, apparently is the easiest solution.

The code:

double myClass::runPythonScrypt()
{
    cv::Mat imageParameter = cv::imread("/home/John/Desktop/image1.jpg", CV_LOAD_IMAGE_COLOR);
    QImage img((uchar*)imageParameter.data, imageParameter.cols, imageParameter.rows, imageParameter.step1(), QImage::Format_RGB32);
    std::string matStdString(imageParameter.begin<unsigned char>(), imageParameter.end<unsigned char>());
    QString matQStr = QString::fromStdString(matStdString);

    QProcess p;
    QStringList params;
    connect(&p, &QProcess::errorOccurred, qApp, &QApplication::aboutQt );
    int a=55;
//I added "this is the end in the string because in the beginning I thought maybe some overflow occured and therefor not the entire image was passed to the process, yet you can see that this sentence gets printed"
    params<< "-c" << "import cv2; import imp; foo = imp.load_source('myTest', '/home/John/fw/demos/myTest.py'); from myTest import myClass; myClassObj = myClass(); print myClassObj.myTestFunction( "+ matQStr +" ) this isthe end;";



        qDebug()<<params;
        p.start("python2", params);
        if(! p.waitForFinished(-1))
        {qDebug()<<"it failedddd";}

        qDebug()<<"error that occured: "<<p.error();

        QString errors = p.readAllStandardError();
        qDebug()<<"occured errors:"<<errors;

        QString p_stdout = p.readAllStandardOutput();


...

}

The generated output:

started recognition thread
("-c", "import cv2; import imp; foo = imp.load_source('myTest', '/home/John/fw/demos/myTest.py'); from myTest import myClass; myClassObj = myClass(); print myClassObj.myTestFunction(

...etc...

����������������������Ѧ����<\u0013\u001B\u0014�������������������������������������������������������������������
����������������������������������������������������������������������u0011\u0017\u0005\b=
*\u0007\u0005\u0016=/\"6=;<@@;;>AA@:311373//+1HcVFPs\u007FeH?z\u007FBY�f\\�oJV��������������������t?
>K\\`RJMTY`a[RSWQMJECBDDIEEEJKN
KJGJHF>@AGFHDC=<89:AA<0/4*%%+/../+##.657>9;=@BBBA@A@><:9<?@@?>?BB;;:88:;<>;;;>>=<;<@@>=<<<;:::;;<998:7337:;<;:
88955555677;;956:954578887879::8533146764441/./0110/--0563/1220./2665420/011222147;FEA>?>;8>=<BGG;04,,-%$&$ \")0
1./3332/,))++)),.)

etc...

10210.,,,-.-/12/*'',-023432-%#')')/04;94:<3.).51/1.((*.10,'1/23547702.0%#0+114; ) this isthe end;")

started recognition thread
QObject::connect: Cannot queue arguments of type 'QProcess::ProcessError'
(Make sure 'QProcess::ProcessError' is registered using qRegisterMetaType().)
it failedddd
error that occured:  QProcess::ProcessError(FailedToStart)
occured errors: ""
name:  ""
certitude:  0
return value:  0
2

EDIT:

The used python script:

#!/usr/bin/env python2

import cv2
import os
import numpy as np


class myClass:

    def __init__(self): pass

    def myTestfunction2(self):     
        image= cv2.imread("/home/John/Desktop/image1.jpg")
        cv2.imshow("image", image)

    def myTestFunction(self, a):
        print('my test function showing passed image as parameter')
        cv2.imshow('a', a)        
        cv2.waitKey(0)
        return ('John', a)

Note that this line, to stream the parameters in stead of the one currently in my software works perfectly fine:

params<< "-c" << "import cv2; import imp; foo = imp.load_source('myTest', '/home/John/fw/demos/myTest.py'); from myTest import myClass; myClassObj = myClass(); print myClassObj.myTestFunction(cv2.imread('/home/John/Desktop/image1.jpg'));";

But it doesn t do exactly what I need, I need to pass a cpp variable rather than using cv2.imread()

I don't see in your code registering metaType line, so please try:

QProcess p;
QStringList params;
qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); // new line
connect(&p, &QProcess::errorOccurred, qApp, &QApplication::aboutQt );

This should solve

QObject::connect: Cannot queue arguments of type 'QProcess::ProcessError'
(Make sure 'QProcess::ProcessError' is registered using qRegisterMetaType().)

problem, so your connection will work and you will see about Qt window, but if for some reasons QProcess wasn't able to start, then it will still have original source of problem, so ^ is just fix for connection.

Anyways QProcess showed you source of problem here:

 error that occured:  QProcess::ProcessError(FailedToStart)

and quite oftenly it means that you try to use some wrong path. Please recheck path or try to use absolutePath , maybe it will solve original problem.

EDIT:

Ok, after your comment it's clear, well linux can't accept unlimited amount of data in arguments, you try to encode here very big amount of info, check this link fe So actually your first approach has normal length and it works, now you pass giantic piece of info and you don't even run python, yes, it's correct path, but system just reject it and show you QProcess::ProcessError(FailedToStart) , of course it could be more convenient with info like ... has too big argument or smth like that, but we don't have it.

Summary:

So your approach is just impossible to implement (also different systems have different limits, so it seems that it's even dangerous (not-portable)), so you need to rewrite your app. I can only suggest to try to save tmp file from Qt and pass tmp path to python script like it was suggested in the link above.

But the best approach probably is just compile OpenCV for C++/Qt and work with raw OpenCV code directly here without tmp files or etc, this will increase performance a lot. Talk about this with your team , if it is some task or do as you wish if it's your personal project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM