Results 1 to 11 of 11

Thread: use of C-function 'strfry' in QT

  1. #1
    Join Date
    Jul 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default use of C-function 'strfry' in QT

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: use of C-function 'strfry' in QT

    Just include the header and use the function normally.

    Regards

  3. #3
    Join Date
    Jul 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: use of C-function 'strfry' in QT

    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

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: use of C-function 'strfry' in QT

    Is lineEditFry allocated?

  5. #5
    Join Date
    Jul 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: use of C-function 'strfry' in QT

    lineEditFry is made (allocated) via the QT-designer and stored in the ui-file...
    Without the strfry-part it displays "Test" into lineEditFry.

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

    Default Re: use of C-function 'strfry' in QT

    Try this:
    Qt Code:
    1. char *buf="Test";
    2. lineEditFry->setText(strfry(buf));
    To copy to clipboard, switch view to plain text mode 

    Or:

    Qt Code:
    1. std::string str = "Test";
    2. char *dat = str.c_ptr();
    3. std::random_shuffle(dat, dat+3);
    4. lineEditFry->setText(dat);
    To copy to clipboard, switch view to plain text mode 

    Or so the same with QByteArray instead of std::string if you're using Qt.

  7. #7
    Join Date
    Jul 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: use of C-function 'strfry' in QT

    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

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

    Default Re: use of C-function 'strfry' in QT

    This works for me:
    Qt Code:
    1. #include <iostream>
    2. #include <string>
    3.  
    4. int main(){
    5. char buf[16];
    6. strcpy(buf, "12345");
    7. std::cout << buf << std::endl;
    8. std::cout << strfry(buf) << std::endl;
    9. return 0;
    10. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jul 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: use of C-function 'strfry' in QT

    Works now!!!
    strfry is a very handy function when it comes to randomizing strings or even integers, making random permutations possible...

    Thanks!
    Regards,
    Misko

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

    Default Re: use of C-function 'strfry' in QT

    I'd say random_shuffle() is more flexible

  11. #11
    Join Date
    Jul 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: use of C-function 'strfry' in QT

    I'll check it out!
    Thx, Misko

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  2. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04
  3. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  4. Qt 4.1.4 plugin QPSQL
    By jcr in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd June 2006, 22:55
  5. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52

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
  •  
Qt is a trademark of The Qt Company.