调用Qfile :: QFile(QStringList)没有匹配函数 [英] No matching function for call Qfile::QFile(QStringList)

查看:212
本文介绍了调用Qfile :: QFile(QStringList)没有匹配函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mainwindow.cpp



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





mainwindow.h

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;
};

推荐答案

QFile 构造函数需要 QString 参数而不是 QStringList



你可能只允许选择 QFileDialog 中的单个文件,并使用 QFileDialog ::将其作为 QString 获取getOpenFileName()(注意最后遗漏的's'。



你的代码也不会在这里编译:

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:
void MainWindow::readtxtfile(QStringList txtfileName)
{
    QFile logfile(loggerfileName);
// ...
}



因为 loggerfileName 可能未定义。





出现此类错误时的提示:

在线查找函数定义( http://doc.qt.io/qt-5/qfile.html [ ^ ])或当光标在函数名称上时按QtCreator中的F1。要快速检查,请将鼠标移到函数名称上以获得带有函数定义的弹出窗口。


because loggerfileName is probably undefined.


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.


非常类似于未定义的对myclass :: myfunction错误的引用 [ ^ ]。请更详细地学习C ++,并 QT文档 [ ^ ],确保正确拼写功能和变量名称。



你需要学习如何自己解决这样的基本问题。它不仅可以帮助您学习语言,还可以帮助您解决问题。
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.


这篇关于调用Qfile :: QFile(QStringList)没有匹配函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆