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("}");@ -
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.
-
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.
-
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?
-
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.