Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Convert a QByteArray to a QVariantList

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Convert a QByteArray to a QVariantList

    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

    Qt Code:
    1. class UserData
    2. {
    3. public:
    4. QByteArray m_fpData;//352bytes
    5. QByteArray& fingerData(){ return m_fpData; }
    6.  
    7. ..more code..
    8. }
    To copy to clipboard, switch view to plain text mode 

    and in a method of another class I have

    Qt Code:
    1. bool Device::registerNewUser(UserData* user)
    2. {
    3. QList<QVariant> paramList;
    4.  
    5. //cardId
    6. QString cardId = QString::number( user->cardId(), 10 );
    7.  
    8. //fp data
    9. QByteArray& b = user->fingerData(); //I get the reference to the bytearray
    10. v.setValue(b); //I add it to a QVariant
    11. QVariantList fingerData;
    12. fingerData.append(v); //and finally to a QVarianList
    13. ...more code...
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 


    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:
    Qt Code:
    1. QVariant::QVariant ( const QByteArray & val )
    2. Constructs a new variant with a bytearray value, val.
    To copy to clipboard, switch view to plain text mode 


    So I don't know how to solve my problem
    Franco Amato

  2. #2
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    Is there anyone that can help?
    Franco Amato

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Convert a QByteArray to a QVariantList

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by wysota View Post
    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
    Franco Amato

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Convert a QByteArray to a QVariantList

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by wysota View Post
    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
    Franco Amato

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Convert a QByteArray to a QVariantList

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by wysota View Post
    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,2ass,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

  9. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    This is the output of generateDocumentation:

    Qt Code:
    1. 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);
    To copy to clipboard, switch view to plain text mode 

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

  10. #10
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs down Re: Convert a QByteArray to a QVariantList

    Well I think Qt can not solve this problem.
    I have to implement it in C#
    Franco Amato

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by franco.amato View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by wysota View Post
    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
    Franco Amato

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by franco.amato View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by wysota View Post
    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
    Franco Amato

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Convert a QByteArray to a QVariantList

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by wysota View Post
    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 )
    Franco Amato

  17. #17
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    QImage ( const QByteArray & array )
    QVariant::QVariant ( const QImage & val )
    Got to keep the loonies on the path ...

  18. #18
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by JD2000 View Post
    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
    Franco Amato

  19. #19
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by franco.amato View Post
    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.

  20. #20
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Convert a QByteArray to a QVariantList

    Quote Originally Posted by franco.amato View Post
    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

Similar Threads

  1. how to convert an int to QByteArray
    By babu198649 in forum Qt Programming
    Replies: 12
    Last Post: 19th September 2014, 09:47
  2. Convert QPixmap to QByteArray ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2014, 08:23
  3. convert QString to QByteArray
    By morgana in forum Qt Programming
    Replies: 5
    Last Post: 2nd March 2011, 13:33
  4. how can we convert QByteArray to Qstring?
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2009, 14:05
  5. Convert from QByteArray to String ?
    By probine in forum Newbie
    Replies: 3
    Last Post: 25th March 2006, 15:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.