PDA

View Full Version : Convert a QByteArray to a QVariantList



franco.amato
10th May 2010, 21:04
Hi to all,
reading the documentation seems easy but I can not convert a QByteArray to a QVariantList.
I know that first I have to convert it to a QVariant and then I append to a QVariantList.

I wrote this code:
in my class declaration I have


class UserData
{
public:
QByteArray m_fpData;//352bytes
QByteArray& fingerData(){ return m_fpData; }

..more code..
}

and in a method of another class I have


bool Device::registerNewUser(UserData* user)
{
QList<QVariant> paramList;

//cardId
QString cardId = QString::number( user->cardId(), 10 );

//fp data
QByteArray& b = user->fingerData(); //I get the reference to the bytearray
QVariant v;
v.setValue(b); //I add it to a QVariant
QVariantList fingerData;
fingerData.append(v); //and finally to a QVarianList
...more code...

}


Unfortunately I get invalid pointer of the QVariant. This is strange to me as from documentation of QVariant a QVariant accept a reference to a QByteArray as constructor:

QVariant::QVariant ( const QByteArray & val )
Constructs a new variant with a bytearray value, val.


So I don't know how to solve my problem

franco.amato
10th May 2010, 21:58
Is there anyone that can help?

wysota
10th May 2010, 22:17
This code doesn't convert a byte array to a variant list. It simply adds the byte array to a variant list in a very complicated way.

franco.amato
11th May 2010, 05:34
This code doesn't convert a byte array to a variant list. It simply adds the byte array to a variant list in a very complicated way.

Wysota so how must I do? help me please

wysota
11th May 2010, 09:53
I don't know what you have to do. I don't know what the byte array contains. I'm merely stating the fact that you are not converting anything, just adding it to a list.

franco.amato
11th May 2010, 15:34
I don't know what you have to do. I don't know what the byte array contains. I'm merely stating the fact that you are not converting anything, just adding it to a list.

Wysota the bytearray contains the fingerprint data.I stored the fingerdata in a QByteArray.
The routine that I call with dinamicCall wants as second argument ( argument 1 as you told ) a QVariantList fingerData so I suppose that I have to convert from QByteArray to QVariantList to pass such variantlist to the routine that I call with dinamicCall.

I'm unable to perform such conversion so I hope you can help me doing it.

Kind Regards

wysota
11th May 2010, 16:02
I can't help you because I don't know what the call expects. Contact the authors of the DLL and ask them. Nobody here will be able to guess what the contents of the list should be just by looking at the function name.

franco.amato
11th May 2010, 16:58
I can't help you because I don't know what the call expects. Contact the authors of the DLL and ask them. Nobody here will be able to guess what the contents of the list should be just by looking at the function name.

I already contacted the author and it gave to me a doc containing the routines list.
The routine I have to call is named
RegUserData.

I list here the parameters wanted by such routine:

CardID(string/10)
OverWrite(0: no overwrite. If ID is already registered, return with result 06.,1: overwrite.)
idxDesignation
idxDepartment
FirstName(string /15)
LastName(string /15)
idxGroup (integer/0~255)
Status(1: Activate, 0: Deactivate)
WorkMode(0:finger+pass ,1:finger,2:pass,3:finger or pass,4:Only Crad,5:Only from external Reader,6:Matching on Mifare card)
WorkTimeStart()
WorkTimeEnd()
EmployeeID
RegisterMode( Finger =1, Password = 2, Finger and Password = 3, Card=4, Max=4)
CheckExpire
ExpireDateStart
ExpireDateEnd
Password(string/10)
NF(Number of fingerprint data per user Max. 2)
TemplateSize
FingerData (byte,User Fingerprint data total size depends on the number of fingerprints registered per user)

The param that give problems to me is the last: FingerData, that should be an array of bytes nothing more.
When I generated the documentation with dumpcpp it says that I have to pass FingerData as QVariantList and here is where I would have your help.

Thanx in advance.

franco.amato
11th May 2010, 17:14
This is the output of generateDocumentation:


bool RegUserData(QString CardID, QVariantList FingerData, bool OverWrite = 0, int idxDesignation = 0, int idxDepartment = 0, QString FirstName = 0, QString LastName = 0, int idxGroup = 0, bool Status = 0, int WorkMode = 0, QString WorkTimeStart = 0, QString WorkTimeEnd = 0, QString EmployeeID = 0, int RegisterMode = 0, bool CheckExpire = 0, QDateTime ExpireDateStart = 0, QDateTime ExpireDateEnd = 0, QString Password = 0, int NF = 0, int TemplateSize = 0);

You can see that it ask for FingerData as second param and of type QVariantList.

franco.amato
11th May 2010, 21:35
Well I think Qt can not solve this problem.
I have to implement it in C# :(

wysota
11th May 2010, 21:50
Well I think Qt can not solve this problem.
I'm sure it can, you just can't blindly do different things hoping that one thing you try might be the correct one. You need to read some documentation, maybe browse and analyze some code and develop a solution to your problem. You won't be given an answer on a silver platter.

I would guess (but only guess) the argument in question awaits a list of byte arrays where each byte array corresponds to a single fingerprint data. But again, that's just a guess based on some logical deduction.

franco.amato
11th May 2010, 21:59
I'm sure it can, you just can't blindly do different things hoping that one thing you try might be the correct one. You need to read some documentation, maybe browse and analyze some code and develop a solution to your problem. You won't be given an answer on a silver platter.

I would guess (but only guess) the argument in question awaits a list of byte arrays where each byte array corresponds to a single fingerprint data. But again, that's just a guess based on some logical deduction.

Wysota I don't want a solution on a silver plate. I only would convert a QByteArray to a QVariantList because I'm not able to do it. I tried many ways without success.
And yes the the argument in question awaits a list of byte arrays where each byte array corresponds to a single fingerprint data. This device store a fingerprint with 352 bytes so my QByteArray has 352 elements and I would convert this 352 elements of my QByteArray to a QVariantList.

Best

wysota
11th May 2010, 22:33
Wysota I don't want a solution on a silver plate. I only would convert a QByteArray to a QVariantList because I'm not able to do it. I tried many ways without success.
Because you first have to know what result you want to achieve before "trying many ways".


And yes the the argument in question awaits a list of byte arrays where each byte array corresponds to a single fingerprint data.
And how do you know that? Maybe it expects the number of byte arrays in the first cell of the list?

franco.amato
11th May 2010, 23:13
Because you first have to know what result you want to achieve before "trying many ways".


And how do you know that? Maybe it expects the number of byte arrays in the first cell of the list?

No, the number of byte arrays is in another cell called template size that's 352


NF(Number of fingerprint data per user Max. 2) //number of fingerprint per user ( maximum 2 )
TemplateSize //352
FingerData (byte,User Fingerprint data total size depends on the number of fingerprints registered per user) = templatesize * NF

wysota
12th May 2010, 08:51
If you are sure you are sending the parameters correctly then dive into the sourcecode of ActiveQt to see when the message you get is generated to see what the possible cause might be. So far we don't even know if it is Qt that generates this message or some other library underneath ActiveQt.

There is also another thing - if you have the dll, maybe you call the function directly instead of using COM?

franco.amato
12th May 2010, 12:07
If you are sure you are sending the parameters correctly then dive into the sourcecode of ActiveQt to see when the message you get is generated to see what the possible cause might be. So far we don't even know if it is Qt that generates this message or some other library underneath ActiveQt.

There is also another thing - if you have the dll, maybe you call the function directly instead of using COM?

Hi,
how can I call the function directly instead using COM? I don't have the associated *.lib and the dll is a com ( I have no experience with com )

JD2000
12th May 2010, 19:06
QImage ( const QByteArray & array )
QVariant::QVariant ( const QImage & val )

franco.amato
12th May 2010, 20:55
QImage ( const QByteArray & array )
QVariant::QVariant ( const QImage & val )

I already tried your idea JD2000 and it doesn't work.
Unfortunately I'm developing the source code in C# that I hate

SixDegrees
12th May 2010, 21:56
I already tried your idea JD2000 and it doesn't work.
Unfortunately I'm developing the source code in C# that I hate

Qt isn't syntactically different in C#; it is written and works exactly the same way as it does anywhere else.

It isn't the language that's at fault.

squidge
12th May 2010, 22:33
how can I call the function directly instead using COM? I don't have the associated *.lib and the dll is a com ( I have no experience with com )Check the exports of the DLL with a PE viewer. If the function is exported, you can link with it. You don't need the .lib

franco.amato
12th May 2010, 22:39
Qt isn't syntactically different in C#; it is written and works exactly the same way as it does anywhere else.

It isn't the language that's at fault.

OK so let me know why this code doesn't work:


//fp data
QByteArray b = user->fingerData(); //<-- return a reference to a QByteArray containing the fingerprint data

QVariant v(b);
QVariantList fingerData;

fingerData.append(v);

I need to convert QByteArray b to QVariantList fingerData.
I'm sure I'm doing some mistake but I don't know which one. Instead in C# I don't have to convert anything.
I prefere C++ to C# but I can not loose 1 week to discover how to do a conversion.

Regards

wysota
13th May 2010, 00:17
What do you mean by "it doesn't work"? It doesn't compile, it crashes when ran?


Instead in C# I don't have to convert anything.
If you were using Qt bindings in C# to access the COM server you'd have to do the exact same conversion. Don't blame the language, as somebody already said. You are using Qt wrapper over C++ (or probably even C) interface to (D)COM. If you have trouble using Qt structures with COM, maybe you should make a bare C/C++ WinAPI call to the COM server. You will probably get some wacky structure in return but maybe this structure will be documented by MSDN good enough for you to understand how to use it.