Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reading CSV file through GUI
Qt 6.11 is out! See what's new in the release blog

Reading CSV file through GUI

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 941 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kripashree
    wrote on last edited by
    #1

    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

    beeckscheB 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      1
      • K kripashree

        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

        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by
        #3

        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);
        }
        
        M 1 Reply Last reply
        2
        • M Offline
          M Offline
          MuhammedSa
          Banned
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • beeckscheB beecksche

            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);
            }
            
            M Offline
            M Offline
            MuhammedSa
            Banned
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved