Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Mainwindow.cpp

void MainWindow::on_pushButton_clicked()
{
   QStringList txtfileName = QFileDialog::getOpenFileNames(this, tr("Open File"),"C://",tr("Txt files (*.txt)"));
   MainWindow mainwindowobj;
   mainwindowobj.readtxtfile(txtfileName);
   //mytestfunctiontocall();
}
void MainWindow::readtxtfile(QStringList txtfileName)
{
    QFile logfile(loggerfileName);
    if (!logfile.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        qDebug() << "Error msg while opening";
           return;
    }

    QTextStream in(&logfile);
    while (!in.atEnd())
    {
        QString line = in.readLine();
         qDebug() << line;
    }

}


mainwindow.h

C#
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    void readtxtfile(QStringList);

    ~MainWindow();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

private:
    Ui::MainWindow *ui;
};
Posted

The QFile constructor expects a QString argument and not a QStringList.

You may only allow selection of a single file in the QFileDialog and get that as QString using QFileDialog::getOpenFileName() (note the missing 's' at the end).

Also your code will not compile here:
C#
void MainWindow::readtxtfile(QStringList txtfileName)
{
    QFile logfile(loggerfileName);
// ...
}

because loggerfileName is probably undefined.

[EDIT]
A tip when you got such errors:
Look up the function definition online (http://doc.qt.io/qt-5/qfile.html[^]) or by pressing F1 inside QtCreator when the cursor is on the function name. For a quick check move the mouse over the function name to get a popup with the function definition.
 
Share this answer
 
v2
Very similar to your question at Undefined reference to myclass::myfunction error[^]. Please study C++ in more detail, and the QT documentation[^], make sure you spell function and variable names correctly.

You need to learn how to solve basic issues like this for yourself. It helps you learn not just the language(s), but problem solving as well.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900