Results 1 to 4 of 4

Thread: How to allow the user to access specific sections of a file in Qt

  1. #1
    Join Date
    Nov 2016
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How to allow the user to access specific sections of a file in Qt

    Hello there, I've coded a bestiary in C++ that allows users to enter in their own monsters and then access those monsters stats through a database but I am having trouble implementing the search functionality in Qt .
    Qt Code:
    1. string search;
    2. int stop(0);
    3. getline (cin, search);
    4. ifstream File ("creatures.txt");
    5. if(File.is_open())
    6. {
    7. string line;
    8. int curLine = 0;
    9. while(getline(File, line))
    10. {
    11. curLine++;
    12.  
    13. if(line.find(search,0)!=string::npos)
    14. {
    15. for(int line_num = 0; line_num = curLine; line_num++)
    16. {
    17.  
    18. if(getline(File, line) && (line_num == curLine))
    19.  
    20. {
    21. stop++;
    22. if (stop==16)
    23. break;
    24. cout<<line<< "\n";
    25. }
    26. else
    27.  
    28. break;
    To copy to clipboard, switch view to plain text mode 
    This code is supposed to allow the user to enter in the name of a monster and then return its stat block and basically i just want the user to do the same thing in Qt except they type the name into a line edit and the stat block appears in another box close by but i cannot figure out what the equivalent code would be to do this in qt so any help would be appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to allow the user to access specific sections of a file in Qt

    Instead of line 3 you would get the text from the line edit.

    Instead of line 24 you could call append() on a QTextEdit.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2016
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to allow the user to access specific sections of a file in Qt

    Thank you, could you also tell me what i would replace lines 9, 13 , and 18 with.
    Last edited by Nicklax; 7th November 2016 at 01:17.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to allow the user to access specific sections of a file in Qt

    Well, you don't necessarily have to change these lines at all, if you want to:
    getline -> QTextStream::readLine()
    string::find() -> QString::indexOf()

    Cheers,
    _

Similar Threads

  1. Replies: 5
    Last Post: 27th December 2013, 15:27
  2. Replies: 0
    Last Post: 23rd December 2013, 11:13
  3. Applicatins directory - non user specific
    By been_1990 in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2013, 00:49
  4. How to access files from specific folder using QContentSet
    By hrudhay in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 30th June 2008, 19:57
  5. Replies: 4
    Last Post: 19th April 2007, 13:17

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.