Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt C++;循环未初始化时读取do_C++_Qt_File Io_Qfile - Fatal编程技术网

C++ Qt C++;循环未初始化时读取do

C++ Qt C++;循环未初始化时读取do,c++,qt,file-io,qfile,C++,Qt,File Io,Qfile,我已经检查了文件的位置是否正确,所以我不知道为什么我的程序不工作。我实际上已经看了几个小时了,但我仍然找不出哪里出了问题。我非常感谢您的任何意见 文本文件中的文本:Bob Janurary 1 2000数学7A 5 41 7 9 8 9 相关代码: void MainWindow::on_pushButton_clicked() { QString name, month, subject, level; int day, year, apages, total, one, t

我已经检查了文件的位置是否正确,所以我不知道为什么我的程序不工作。我实际上已经看了几个小时了,但我仍然找不出哪里出了问题。我非常感谢您的任何意见

文本文件中的文本:Bob Janurary 1 2000数学7A 5 41 7 9 8 9

相关代码:

void MainWindow::on_pushButton_clicked()
{
    QString name, month,  subject, level;
    int day, year, apages, total, one, two, three, four, five, six, seven, eight, nine, ten;

    QFile file("C:/Users/brandan/Desktop/GUIPrograms/Kumon.txt");

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QTextStream stream(&file);
        QString line;

        do
        {
        qDebug() << "test";
        line = stream.readLine();
        qDebug() << line;
        } while(!line.isNull());
    }

}
void主窗口::在按钮上点击()
{
Q字符串名称、月份、主题、级别;
一天、一年、一年、一年、一年、一年、一年、二年、三年、四年、五年、六年、七年、八年、九年、十年;
QFile文件(“C:/Users/brandan/Desktop/GUIPrograms/Kumon.txt”);
如果(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
QTextStream流(&文件);
QString线;
做
{

qDebug()您正在检查文件是否正确打开

if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
因此,只有当文件未正确打开时,才会执行代码

if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {

你所说的“不工作”是什么意思?QDebug没有输出任何东西。另外,为什么你的条件是
如果(!file.open(…)
?你正在检查打开是否失败,然后开始读取文件。相反,只需执行
如果(file.open(…)
。为什么要使用!not操作符?你确定是在调试模式下编译的吗?