C:\\Qt\\Qt5.2.1\\Tools\\QtCreator\\bin\\conway-master\\mainwindow.cpp:56: error:
ID: 3556381 • Letter: C
Question
C:QtQt5.2.1ToolsQtCreatorinconway-mastermainwindow.cpp:56: error: 'class QString' has no member named 'toAscii' file.write(game->dump().toAscii()); ^
#include <QTextStream>
#include <QFileDialog>
#include <QDebug>
#include <QColor>
#include <QColorDialog>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
currentColor(QColor("#000")), game(new GameWidget(this))
{ ui->setupUi(this);
QPixmap icon(16, 16);
icon.fill(currentColor);
ui->colorButton->setIcon( QIcon(icon) );
connect(ui->startButton, SIGNAL(clicked()), game,SLOT(startGame()));
connect(ui->stopButton, SIGNAL(clicked()), game,SLOT(stopGame()));
connect(ui->clearButton, SIGNAL(clicked()), game,SLOT(clear()));
connect(ui->iterInterval, SIGNAL(valueChanged(int)), game, SLOT(setInterval(int)));
connect(ui->cellsControl, SIGNAL(valueChanged(int)), game, SLOT(setCellNumber(int)));
connect(game,SIGNAL(environmentChanged(bool)),ui->cellsControl,SLOT(setDisabled(bool)));
connect(game,SIGNAL(gameEnds(bool)),ui->cellsControl,SLOT(setEnabled(bool)));
connect(ui->colorButton, SIGNAL(clicked()), this, SLOT(selectMasterColor()));
connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(saveGame()));
connect(ui->loadButton, SIGNAL(clicked()), this, SLOT(loadGame()));
ui->mainLayout->setStretchFactor(ui->gameLayout, 8);
ui->mainLayout->setStretchFactor(ui->setLayout, 2);
ui->gameLayout->addWidget(game);
}
MainWindow::~MainWindow()
{ delete ui;
}
void MainWindow::saveGame()
{ QString filename = QFileDialog::getSaveFileName(this,
tr("Save current game"), QDir::homePath(),
tr("Conway's Game *.life Files (*.life)")); if(filename.length() < 1)
return;
QFile file(filename);
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
return;
QString s = QString::number(game->cellNumber())+" ";
file.write(s.toAscii());
file.write(game->dump().toAscii());
QColor color = game->masterColor();
QString buf = QString::number(color.red())+" "+
QString::number(color.green())+" "+
QString::number(color.blue())+" ";
file.write(buf.toAscii());
buf.clear();
buf = QString::number(ui->iterInterval->value())+" ";
file.write(buf.toAscii());
file.close();
}
void MainWindow::loadGame()
{ QString filename = QFileDialog::getOpenFileName(this,
tr("Open saved game"), QDir::homePath(),
tr("Conway's Game Of Life File (*.life)")); if(filename.length() < 1)
return;
QFile file(filename);
if(!file.open(QIODevice::ReadOnly))
return;
QTextStream in(&file);
int sv;
in >> sv;
ui->cellsControl->setValue(sv);
game->setCellNumber(sv);
QString dump="";
for(int k=0; k != sv; k++) { QString t;
in >> t;
dump.append(t+" ");
}
game->setDump(dump);
int r,g,b; // RGB color
in >> r >> g >> b;
currentColor = QColor(r,g,b);
game->setMasterColor(currentColor); // sets color of the dots
QPixmap icon(16, 16); // icon on the button
icon.fill(currentColor); // fill with new color
ui->colorButton->setIcon( QIcon(icon) ); // set icon for button
in >> r; // r will be interval number
ui->iterInterval->setValue(r);
game->setInterval(r);
}
void MainWindow::selectMasterColor()
{ QColor color = QColorDialog::getColor(currentColor, this, tr("Select color of figures")); if(!color.isValid())
return;
currentColor = color;
game->setMasterColor(color);
QPixmap icon(16, 16);
icon.fill(color);
ui->colorButton->setIcon( QIcon(icon) );
}
Explanation / Answer
which version of Qt you are using
toAscii() method in QString class available only from Qt 4.1 onwards..
please check your Qt Version.
in Qt 5.2.1 toAscii() method is removed ...
Please use toUtf8() method in stead of that....
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.