0

How to convert from cryptopp::integer to QString?

If it's important I work on Mac OS. I absolutely don't know what to do, only trying to use QCA, but it wasn't good enough!

László Papp
  • 51,870
  • 39
  • 111
  • 135
  • GetBits() with BitCount() and then QString::number() seem to be what you are looking for. – László Papp Dec 22 '13 at 20:22
  • Maybe you can deduce from the reverse - http://stackoverflow.com/questions/3398304/qt-and-cryptopp-converting-qstring-qchar-to-be-accepted-with-cryptopp – Leeor Dec 22 '13 at 21:27
  • @Leeor yes, that is useful, but not enough fool solution. – user1700480 Dec 22 '13 at 22:07
  • @LaszloPapp I am weak in cryptopp and don't know this functions.But now I try to realize you suggestion. Thanks a lot! – user1700480 Dec 22 '13 at 22:09
  • @Leeor: how is that thread related? I understand it is the google result which comes up at the beginning, but that does not make it solve this issue. :) – László Papp Dec 23 '13 at 02:58
  • @LaszloPapp, where did I say it solves the issue? Just checked for dups (which it isn't) – Leeor Dec 23 '13 at 06:00
  • @LaszloPapp I solved my problem. I think your way is the best way working with QString and cryptopp:integer. Thank you very much! You really help me! – user1700480 Dec 23 '13 at 06:26

2 Answers2

1

How to convert from cryptopp::integer to QString?

You could also do something like this:

CryptoPP::Integer i = 1;
i <<= 128;
i--;
i *= 3;

ostringstream oss;
oss << std::hex << i;

QString qs(oss.str().c_str());
jww
  • 97,681
  • 90
  • 411
  • 885
0

Based on your feedback to my comment, it seems that you need three steps.

1) Call the BitCount() method to get the number of bits in the integer.

2) Then, you can get all the bits by using the GetBits() method.

3) Once that is done, you can call use the QString::number() method to get the actual integer into the desiredQString` as the return value of the static method.

László Papp
  • 51,870
  • 39
  • 111
  • 135