View Full Version : use of C-function 'strfry' in QT
Misko
13th August 2007, 22:02
Hi,
In a program i want to use the strfry-function. Therefor i've included string.h and used 'extern "C"' to be able to use this function.
But i don't think this is the right way to do it...
Anyone with an idea?
Regards,
Misko
marcel
13th August 2007, 22:24
Just include the header and use the function normally.
Regards
Misko
14th August 2007, 08:46
Hi,
In QDevelop i've done: #include <string> and then used the function like this:
lineEditFry->setText(strfry("Test"));
But it gives me a segmentation fault...
Regards,
Misko
marcel
14th August 2007, 08:49
Is lineEditFry allocated?
Misko
14th August 2007, 08:57
lineEditFry is made (allocated) via the QT-designer and stored in the ui-file...
Without the strfry-part it displays "Test" into lineEditFry.
wysota
14th August 2007, 11:07
Try this:
char *buf="Test";
lineEditFry->setText(strfry(buf));
Or:
std::string str = "Test";
char *dat = str.c_ptr();
std::random_shuffle(dat, dat+3);
lineEditFry->setText(dat);
Or so the same with QByteArray instead of std::string if you're using Qt.
Misko
14th August 2007, 19:11
Even in C++ it gives me a segmentation fault:
#include <iostream>
#include <string>
using namespace std;
int main()
{
char *buf = "1235";
cout << strfry(buf) << endl;
}
I know this isn't a real QT-problem, but maybe you can help me out on this one!
I certainly would appreciate!
Regards,
Misko
wysota
14th August 2007, 20:25
This works for me:
#include <iostream>
#include <string>
int main(){
char buf[16];
strcpy(buf, "12345");
std::cout << buf << std::endl;
std::cout << strfry(buf) << std::endl;
return 0;
}
Misko
14th August 2007, 23:04
Works now!!!
strfry is a very handy function when it comes to randomizing strings or even integers, making random permutations possible...
Thanks!
Regards,
Misko
wysota
15th August 2007, 02:13
I'd say random_shuffle() is more flexible :)
Misko
15th August 2007, 13:42
I'll check it out!
Thx, Misko
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.