Results 1 to 2 of 2

Thread: How do I sort Data in a CSV by groups using QT?

  1. #1
    Join Date
    Apr 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Thumbs up How do I sort Data in a CSV by groups using QT?

    I have CSV file of servers separate by \r\n with unwanted word *serverlist" at the beginning of the file and unwanted "*" at the end.

    Qt Code:
    1. *serverlist\r\n#HostName,IP,Score,Ping,Speed,CountryLong,CountryShort\r\nserver2x.selfip.xx,111.100.240.10,605268,8,380099315,Japan,JP\r\nserve2x.selfip.xx,39.110.61.222,602280,3,625856265,Japan,JP\r\nserver2x.selfip.xx,46.5.0.129,400121,15,15754028,Germany,DE\r\n*\r\n
    To copy to clipboard, switch view to plain text mode 

    Am downloading this from a remote server using QNetworkAccessManager and QNetworkReply

    Qt Code:
    1. QString csvdata(reply->readAll());
    2.  
    3. QStringList srvlist;
    4. for(QString data : csvdata.replace("\r","").split("\n")){
    5. srvlist =data.split(',');
    6. //Having Got a First List in the Firts Iteration,How Can I get each item in the list? so as I can send it to my Database table using below Sql query
    7. // INSERT INTO serverlisttable (id, hostname, IP,score...) VALUES (1, 'listitem at [0]', 'list item at [1]'...)
    8. }
    To copy to clipboard, switch view to plain text mode 


    My Goal is to Store this type of Data by Group into a Database in this Format for easy searching

    Qt Code:
    1. ID HostName IP Score Ping Speed CountryLong CountryShort
    2.  
    3. 1 server2x.selfip.xx 111.100.240.10 605268 8 380099315 Japan JP
    4.  
    5. 2 serve2x.selfip.xx 39.110.61.222 602280 3 625856265 Japan JP
    To copy to clipboard, switch view to plain text mode 

    Your help will be appreciated
    Last edited by njunwa1; 30th April 2017 at 00:02.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How do I sort Data in a CSV by groups using QT?

    So what's the problem? You basically wrote the code in your // INSERT comment. 'listitem at [0]' is simply svrlist[0] or svrlist.at(0). Read the documentation for QList. As always in Qt, if you don't see the method you need in the class you are looking at, check its base classes.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QGraphicsEffect for nested groups
    By japcrword in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2015, 08:50
  2. call data() function after QHeaderview Sort
    By poporacer in forum Qt Programming
    Replies: 6
    Last Post: 28th April 2011, 02:39
  3. Sort huge data use QSortFilterProxyModel
    By jiaorenjie in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2011, 03:56
  4. What groups, bands do you listen to?
    By ComaWhite in forum General Discussion
    Replies: 3
    Last Post: 1st November 2010, 16:44
  5. can't get right data after sort
    By wirasto in forum Qt Programming
    Replies: 5
    Last Post: 28th June 2009, 19:19

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.