调用Qfile :: QFile(QStringList)没有匹配函数 [英] No matching function for call Qfile::QFile(QStringList)
本文介绍了调用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 ::将其作为
(注意最后遗漏的's'。QString
获取getOpenFileName()
你的代码也不会在这里编译:
TheQFile
constructor expects aQString
argument and not aQStringList
.
You may only allow selection of a single file in theQFileDialog
and get that asQString
usingQFileDialog::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屋!
查看全文