简单的QT从文本文件程序中读取不编译
Simple Qt Read From Text File Program not Compiling
基本上我制作了一个简单的程序来读取一行文本,但是每当我运行程序时,我都会收到一个错误
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;
}
}
从qfile的API信息中,似乎应该使用,例如QTextStream
对象使用<<
和>>
操作员。关于调试错误:QDebug
是类的名称,而不是内存中的实例。从QDebug页面中,您可以改用qDebug()
。
QDebug
是一种类型,您需要使用QDebug
的实例,该实例从函数qDebug()
检索:
qDebug() << a << b << c; ^^^^^^^^
相关文章:
- 如何在C++编译时读取文件?
- 在C++中读取文件系统时出现问题(Boost 未编译)
- Qt 静态编译无法读取路径
- X86系统的编译读取线(静态模式)
- 在编译时读取文件(constexpr 或其他)
- 编译代码时"No matching function for call"。[QTS天线端口打开读取]
- 如果在类 temlpate 中使用,fstream 是否会在编译时通过读取和写入来访问 hardrive?
- C 中带有读取函数的编译误差
- 无法使用 OpenVino 推理编译 OpenCV,无法读取 cpuid.txt
- 双击编译C++ Unix 可执行文件不会打开现有文件以从中读取信息
- 编译C 源的问题将.OFF文件转换为XML Android OpenGL ES可读取的问题
- 简单的QT从文本文件程序中读取不编译
- C++程序读取ppm和pgm文件,对其进行操作并输出.编译错误
- ostringstream 运算符 [] 在尝试读取缓冲区时给出编译错误
- 使用 std::ifstream 读取文件以编译 OpenGL 着色器不起作用
- 使用CPP读取CSV文件,使用CMake文件编译代码
- 是否可以在编译时读取文件
- c++读取文件时的编译错误
- 问题读取预编译的着色器文件ID3DBlob
- 在本例中,如何在编译时从文本文件读取数据