You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qt汽车共享项目中调用RegData类成员函数出现类型错误:request for member 'setLogin' in 'givedata' which is of non-class type 'RegData()'

Fixing the "request for member 'setLogin' in non-class type 'RegData()'" Error

Hey there, let's break down what's causing this error and how to fix it quickly!

The Root Cause

Your error message clearly points to the core issue:

C:\Users\david\Documents\Carsharring_files\mainwindow.cpp:165: error: request for member 'setLogin' in 'givedata', which is of non-class type 'RegData()'

In your mainwindow.h, you declared givedata as a member function that returns a RegData object, not as a RegData class member variable. When you try to call givedata.setLogin(), the compiler sees givedata as a function name (not an object), so it can't find the setter methods that belong to the RegData class.

Step-by-Step Fix

1. Correct the Member Declaration in mainwindow.h

Find where you declared givedata in your MainWindow class. You probably have something like this:

class MainWindow : public QMainWindow
{
    // ... other class members ...
    RegData givedata(); // This is a function declaration, NOT a variable
};

Change it to a RegData member variable by removing the parentheses:

class MainWindow : public QMainWindow
{
    // ... other class members ...
    RegData givedata; // Now this is a valid RegData object instance
};

2. Update the Login Validation Logic in mainwindow.cpp

Now that givedata is a proper RegData object, you can safely call its setter methods when login succeeds:

// Inside your login validation loop
if (loginCredentialsMatch) {
    givedata.setLogin(loginline);
    givedata.setEmail(emailline);
    givedata.setPassword(passwordline);
    givedata.setBalance(fetchedUserBalance); // Replace with your actual balance value from the file
}

Optional: Add a Getter Method (If Needed)

If you need to access this RegData instance elsewhere in your code (like displaying the balance in the main menu), add a getter function to your MainWindow class:

// In mainwindow.h
class MainWindow : public QMainWindow
{
    // ...
    RegData getRegData() const { return givedata; } // Getter to access the RegData instance
};

Why This Works

By changing givedata from a function declaration to a class member variable, you're creating an actual instance of the RegData class inside your MainWindow. This instance has full access to all the setter and getter methods you defined in the RegData class, so the compiler will no longer throw that "non-class type" error.

内容的提问来源于stack exchange,提问作者Nedaxses

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 01:17:49