从文本文件程序读取的简单Qt不编译

时间:2014-01-26 15:34:19

标签: c++ qt

基本上我做了一个简单的程序来读取一行文本,但每当我运行程序时,我都会收到错误

no match for 'operator>>' (operand types are 'QFile' and 'QString')
while(file >> name >> month >> day >> year >> subject >> level >> apages >> total >> one >> two >> three >> four >> five >> six >> seven >> eight >> nine >> ten)

和另一个错误:

expected unqualified-id before '<<' token
         QDebug << QString(name);

我一直想在网上找一些东西一小时,但我真的找不到任何有效或我能理解的东西。我真的很感激可以提供的任何输入。

相关代码:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtCore/QCoreApplication>
#include <QtCore>
#include <QFile>
#
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

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))
        return;

    while(file >> name >> month >> day >> year >> subject >> level >> apages >> total >> one >> two >> three >> four >> five >> six >> seven >> eight >> nine >> ten)
    {
        QDebug << name << month << day << year << subject << level << apages << total << one << two << three << four << five << six << seven << eight << nine << ten;
    }

}

2 个答案:

答案 0 :(得分:0)

QDebug是一种类型,您需要使用从QDebug函数中检索到的qDebug()实例:

qDebug() << a << b << c;
^^^^^^^^

答案 1 :(得分:0)

QFile的API信息中,您似乎应该使用例如使用QTextStream<<运算符的>>对象。关于调试错误:QDebug是类的名称,而不是内存中的实例。在QDebug页面上,您似乎可以使用qDebug()

相关问题