このエラーが発生し続けます:
cannot call member function 'QString Load::loadRoundsPlayed()'without object
今はc ++とqtにかなり慣れていないので、これが何を意味するのかわかりません。別のクラスから関数を呼び出して、いくつかの lcdNumbers に番号を設定しようとしています。関数を保持する Load.cpp は次のとおりです。
#include "load.h"
#include <QtCore>
#include <QFile>
#include <QDebug>
Load::Load() //here and down
{}
QString Load::loadRoundsPlayed()
{
QFile roundsFile(":/StartupFiles/average_rounds.dat");
if(!roundsFile.open(QFile::ReadOnly | QFile::Text))
{
qDebug("Could not open average_rounds for reading");
}
Load::roundsPlayed = roundsFile.readAll();
roundsFile.close();
return Load::roundsPlayed;
}
Load.h は次のとおりです。
#ifndef LOAD_H
#define LOAD_H
#include <QtCore>
class Load
{
private:
QString roundsPlayed; //and here
public:
Load();
QString loadRoundsPlayed(); //and here
};
#endif // LOAD_H
そして最後に、関数を呼び出す場所:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "load.h"
#include <QLCDNumber>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
MainWindow::startupLoad();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::startupLoad()
{
ui->roundPlayer_lcdNumber->display(Load::loadRoundsPlayed()); //right here
}
これを実行すると、そのエラーが発生します。それが何を意味するのかわからないので、誰かが助けてくれたらありがたいです。ありがとう。