Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Reading CSV file through GUI



  • Re: CSV file from QT

    Hi,

    I am new to QT,can anyone let me know how to open csv file and read the csv file by giving a pushbutton option from the GUI?

    Thanks In advance

    Regards,
    Kripashree


  • Qt Champions 2017

    Nothing to do with Qt. It is normal file processing. Can you check QFile class in Qt & see how to open, read, print, process the contents of the file ? If you are ready with this, you can write slot to do the file processing. You can connect from PushButton signal to slot.



  • Hi @kripashree ,

    to open a file use QFile.

    Following the example on the page

    MainWindow::onButtonClicked()
    {
        QFile file("in.csv");
        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
            return;
    
        while (!file.atEnd()) {
            QByteArray line = file.readLine();
            QList<QByteArray> values = line.split(";"); // depending on your sperator in the csv file
            // do whatever you want with the values
        }
    }
    

    The onButtonClicked() function needs to be connected with a signal of your button. In general this connection is set in the constructor of your main window class. Eg:

    MainWindow::MainWindow()
    {
        connect(buttonPointer, &QPushButton::clicked, this, &MainWindow::onButtonClicked);
    }
    

  • Banned

    This post is deleted!

  • Banned

    This post is deleted!

Log in to reply