char* to QString: conversion
Hi
While calling dll file from vb.net I am passing a string value to the qt dllas follows:
Code:
<DllImport("G:\Varen_CS\02_Projects\01_Softwares\highFreqTrad\test\debug\test.dll", _
CharSet:=CharSet.Auto, _
CallingConvention:=CallingConvention.StdCall)> _
Private Shared Function _ZN11QtEngineDll7randIntEv(ByRef u As String) As String
End Function
Now my qtcode goes as follows:
Code:
QtEngineDll::QtEngineDll(const char* url)
{
m = url;
}
const char* QtEngineDll::randInt()
{
file.write(result + "\n");
return result;
}
But the file output is something like this:
Code:
[07/03/10 - 12:03:46], Abhijit U‰åVSēpÂE¸‰$èÂT
Can you pls tell me what is the wrong that I am committing in the code?
Thanks in advance.
Re: char* to QString: conversion
QByteArray stores raw bytes (including '\0's) and traditional 8-bit '\0'-terminated strings.
You can't get Unicode character whit it.
Re: char* to QString: conversion
Use instead QString::fromUtf8 ( const char * str, int size = -1 ) .
Read the Qt doc.
Re: char* to QString: conversion
Thanks toutarrive.
However if I use the following:
Code:
const char* test = "Abhijit";
result
= QString::number(d.
size());
return result;
everything is going fine. But if instead of defining test in the program itself, if I pass test value as an parameter from vb.net then some absurd result is thrown. Can anybody put some light on this?
Thanks in advance.
Re: char* to QString: conversion
Can You guarantee that in QtEngineDll::randInt() pointer delivered to QtEngineDll constructor is steel point to this same data ?
Maybe it will be better to create QByteArray object in QtEngineDll constructor.
Re: char* to QString: conversion
Hi Lisiok
Can u pls demonstrate the same in this context.
Any way thnks for suggesting a better method.
Re: char* to QString: conversion
I don't see in your code where you are handling the unicode characters.
4 Attachment(s)
Re: char* to QString: conversion
Hi
The problem as far as I have found is in passing the parameter may it be string or integer. The argument value is not at all passed properly. Even if I passed some integer value it is taking it as 1 and not the value passed actually.
Cant understand whether it is a problem in my vb.net call or the dll function definition.
I have attached the files required for building the DLL file in Qt 4. Note that the entry point name is taken from the dll file reader.
If I have committed some mistake in making the DLL file can you pls modify it.
Thanks in advance.
Re: char* to QString: conversion
I'm not familiar with mating .Net code to straight C++ code, but it seems that the parameter list here:
Code:
Private Shared Function _ZN11QtEngineDll7randIntEv(ByRef u As String) As String
(one parameter) doesn't match the one here:
Code:
const char* QtEngineDll::randInt()
(no parameter, but probably requires an implied this pointer)
Any value passed by VB.Net in the u parameter has nowhere to go in the C++ (except perhaps being misinterpreted as a this pointer).
Other things to ponder: Your randInt() tries to dump a string set in the constructor to a file, and not a parameter passed to the method. Where is your object constructed? How is VB.Net setting a "this" pointer when it calls the randInt() method?
Re: char* to QString: conversion
Hi ChrisW67
The function mentioned by you is the older one. I have recently attached the new file where I just want to pass some integer value.
Passing integer value is also having error.
What I now think is to pass the parameter using some pointer. But I have no idea about reading pointer variables in Qt. Can you pls put some light on the same.
Thanks in advance.