Results 1 to 6 of 6

Thread: Loading CSV file on start of application

  1. #1
    Join Date
    Jul 2013
    Posts
    27
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Loading CSV file on start of application

    Hello friends,
    I am importing my language CSV file in Table widget. I don't want to wait for the open action, what i want is to load the CSV file as soon as i start the main application. Here is my CSV file processing code. Kindly let me know what to do, or atleast a few pointers. Thank you very much.

    QString fileName = QFileDialog::getOpenFileName(this, ("Open File"), NULL, ("Language(*.csv)"));
    QString data;
    QFile importedCSV(fileName);
    QStringList rowOfData;
    QStringList rowData;
    data.clear();
    rowOfData.clear();
    rowData.clear();

    if (importedCSV.open(QFile::ReadOnly))
    {
    data = importedCSV.readAll();
    rowOfData = data.split("\n"); //Value on each row
    importedCSV.close();
    }

    for (int x = 0; x < rowOfData.size(); x++) //rowOfData.size() gives the number of row
    {
    rowData = rowOfData.at(x).split(";"); //Number of columns
    // int r=rowData.size();
    for (int y = 0; y < rowData.size(); y++)
    {
    mUI.languageTable->item(x,y)->setText(rowData[y]);

    }
    }

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Loading CSV file on start of application

    Qt Code:
    1. //QString fileName = QFileDialog::getOpenFileName(this, ("Open File"), NULL, ("Language(*.csv)"));
    2. fileName = "English.csv"; //<<<<<<<<<<<<<<<<<
    3. QString data;
    4. QFile importedCSV(fileName);
    5. QStringList rowOfData;
    6. QStringList rowData;
    7. data.clear();
    8. rowOfData.clear();
    9. rowData.clear();
    10.  
    11. if (importedCSV.open(QFile::ReadOnly))
    12. {
    13. data = importedCSV.readAll();
    14. rowOfData = data.split("\n"); //Value on each row
    15. importedCSV.close();
    16. }
    17.  
    18. for (int x = 0; x < rowOfData.size(); x++) //rowOfData.size() gives the number of row
    19. {
    20. rowData = rowOfData.at(x).split(";"); //Number of columns
    21. // int r=rowData.size();
    22. for (int y = 0; y < rowData.size(); y++)
    23. {
    24. mUI.languageTable->item(x,y)->setText(rowData[y]);
    25.  
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jul 2013
    Posts
    27
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Loading CSV file on start of application

    Hello Santosh,
    Thank you for the changes, but commenting the 1st line you mentioned, it gave me an error. So i declared the filename as QString. But it didnt work. My main question is how to call this function, so it can automatically look for the CSV file which is already in the qt project folder, from where i am working. Something similar to a qrc file. Thank you for your time.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Loading CSV file on start of application

    My main question is how to call this function, so it can automatically look for the CSV file which is already in the qt project folder, from where i am working. Something similar to a qrc file.
    If you want to get the file name automatically you need not call QFileDialog::getOpenFileName(), this is needed only when operator/user has to select the file. If you automatically need the then use QDir::entryInfoList() get all the files in the directory and pick one from it.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Jul 2013
    Posts
    27
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Loading CSV file on start of application

    Thank you Santosh once again. Just one last question, when & where do i call the function which is handling all this code. I managed to get the entryInfoList operational, now it is only looking for csv files in my directory, but because i am not calling the function anywhere, its not executing. The function takes no parameters and does not return anything. Thank you so much for your time.

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Loading CSV file on start of application

    It is trival to call instead of QFileDialog::getOpenFileName()
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  7. The following user says thank you to Santosh Reddy for this useful post:

    akshaysulakhe (18th July 2013)

Similar Threads

  1. to set start up application in beagleboard
    By mehkants in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 8th September 2012, 06:07
  2. Replies: 3
    Last Post: 2nd August 2012, 13:46
  3. Start application in QT
    By eltecprogetti in forum Qt Programming
    Replies: 2
    Last Post: 12th April 2012, 09:46
  4. Start application when OS starts
    By sophister in forum Qt Programming
    Replies: 16
    Last Post: 13th April 2011, 06:38
  5. How to start external application from QT?
    By TomASS in forum Newbie
    Replies: 10
    Last Post: 7th November 2009, 17:57

Tags for this Thread

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.