Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8314495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:50:11+00:00 2026-06-08T20:50:11+00:00

I keep getting this error: cannot call member function ‘QString Load::loadRoundsPlayed()’without object Now im

  • 0

I keep getting this error:

cannot call member function 'QString Load::loadRoundsPlayed()'without object

Now im pretty new to c++ and qt so im not sure what this means. I am trying to call a function from another class to set the number on some lcdNumbers. Here is the Load.cpp which holds the function:

#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;
}

And here is the 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

And finally the place where i call the function:

    #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
    }

When i run this i get that error. Im not sure what it means so if anyone could help i would be thankfull. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:50:12+00:00Added an answer on June 8, 2026 at 8:50 pm

    The error description is pretty clear

    cannot call member function ‘QString Load::loadRoundsPlayed()’without object

    You cannot call member functions, that are not static, without creating instance of the class.


    Looking at you code, you probably need to do this:

    Load load;
    ui->roundPlayer_lcdNumber->display(load.loadRoundsPlayed()); //right here
    

    There are two other options:

    • make loadRoundsPlayed static and roundsPlayed static, if you don’t want them to be associated with the concrete instances OR
    • make loadRoundsPlayed static and return QString by copy, that will be locally created inside the function. Something like

    :

    QString Load::loadRoundsPlayed()
    {
        QFile roundsFile(":/StartupFiles/average_rounds.dat");
    
        if(!roundsFile.open(QFile::ReadOnly | QFile::Text))
        {
            qDebug("Could not open average_rounds for reading");
        }
    
        QString lRoundsPlayed = roundsFile.readAll();
        roundsFile.close();
        return lRoundsPlayed;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On the query below I keep getting this error: Cannot read the next data
I am programming under Delphi Prism for Mono. I keep getting this error, Cannot
I keep getting this error: cannot convert parameter 1 from 'char' to 'LPCWSTR' int
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting this error and have no idea why. I googled and scanned
I keep getting this error on emulator: I copied this from a tutorial and
I keep getting this error Error in readPNG(destfile) : libpng error: PLTE: CRC error
I keep getting this error with my Play 2.0 application: play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[MatchError:
I keep getting this error when using django templates in Google App Engine: TemplateSyntaxError:
I keep getting this error in the $('#savetickets-list') line. I want to dynamically add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.