Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Converting void pointer to qstring



  • hi to everyone
    i have a void pointer(argv) and i have a counter of its elements(argc)
    i use this code to parse it and turn it to qstring, this is one of functions of testcon application
    it compiled successfully
    but when i ran a programm it hang
    what is its problem?
    @String paramlist;
    VARIANT params = (VARIANT)argv;
    for (int a = argc-1; a >= 0; --a) {
    if (a == argc-1)
    paramlist = QLatin1String(" - {");
    QVariant qvar = VARIANTToQVariant(params[a], 0);
    paramlist += QLatin1String(" ") + qvar.toString();
    if (a > 0)
    paramlist += QLatin1String(",");
    else
    paramlist += QLatin1String(" ");
    }
    if (argc)
    paramlist += QLatin1String("}");@


  • Moderators

    as a side note, you can use "qApp->arguments()":http://developer.qt.nokia.com/doc/qt-4.7/qcoreapplication.html to get an already parsed QStringList of arguments.



  • no , the function is'nt my main function
    it is another function


  • Moderators

    the qApp pointer is globally accessible.



  • i know the qapp pointer is globally accessible but argv and argc is'nt argumens of my main functions
    i should write my code like this to more understand:
    @void func(const QString &gg,int argc,void *argv)
    {
    String paramlist;
    VARIANT params = (VARIANT)argv;
    for (int a = argc-1; a >= 0; --a) {
    if (a == argc-1)
    paramlist = QLatin1String(" - {");
    QVariant qvar = VARIANTToQVariant(params[a], 0);
    paramlist += QLatin1String(" ") + qvar.toString();
    if (a > 0)
    paramlist += QLatin1String(",");
    else
    paramlist += QLatin1String(" ");
    }
    if (argc)
    paramlist += QLatin1String("}");
    }@



  • How should we know the problem? We do not even know what's behind your void pointer, not to mention what your VARIANT type is nor the VARIANTToQVariant and how it is organized.

    Oh, and your code would be much more readable, if you would use proper indenting. I would not find a bug in that mess either.



  • i know the void arguments is an integer but it get me error



  • Bravo! Now we know exceptionally more and can solve your problem...

    Sorry, for being sarcastic, but do your really expect that we can comment on your problem with that much information you gave us? Did you try yourself using a debugger and stepping through the code?



  • If yoiu areguments are integers, why do you cast them to VARIANT pointers? Are you talking about COM VARIANTS? If yes, it seams, you don't know their structure, they are not integers.



  • yes it is a com variants
    what should i do?



  • That depends.
    I have no idea how your input looks like.,
    If it is ints, don't cast them to VARIANT!



  • You can only savely cast to a known data structure. If you don't have access to that structure (for instance by including a header describing the structure), there is no save way to cast to anything. So: find out what the input data is, and how it is represented. Only then start thinking about casting to it.



  • the documentation says it is a integer but
    for example when it should send me 99 it get me 206
    and when it should send me 200 it get me 63
    i don't know what does it mean



  • We have no idea which program sends you messages and how to interpret them.
    Contact the one who wrote it.


Log in to reply