RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 584435
Accepted
Matty
Matty
Asked:2020-10-30 07:15:48 +0000 UTC2020-10-30 07:15:48 +0000 UTC 2020-10-30 07:15:48 +0000 UTC

创建采用自定义类的成员函数的问题

  • 772

有一个类继承了QGroupBox(不知道有没有关系),还有一个类就是简单的为他们存储数据和几个函数。我需要将第二个类的实例传递给第一个类的方法。

MattyGroupBox.h

#ifndef MATTYGROUPBOX_H
#define MATTYGROUPBOX_H

    public QGroupBox
{
public:
    MattyGroupBox();
    //void fillFrame(MattyNote & ThisNote);
    ~MattyGroupBox();
private:
    void buildFrame();
    QLabel* NoteTitleLabel;
    QLabel* NoteTypeLabel;
    QLabel* NoteCrTimeAndDateLabel;
    QLabel* NoteEventTimeAndDateLabel;
    QLabel* NoteTextLabel;
    QSpacerItem* horizontalSpacer_1;
    QSpacerItem* horizontalSpacer_2;
    QSpacerItem* verticalSpacer;
    QPushButton* editNoteButton;
    QPushButton* deleteNoteButton;
    QHBoxLayout* horizontalLayout_1;
    QHBoxLayout* horizontalLayout_2;
    QVBoxLayout *verticalLayout;
    QGridLayout *gridLayout;

};

#endif // MATTYGROUPBOX_H

MattyGroupBox.cpp

#include "stdafx.h"
#include "MattyGroupBox.h"
#include "MattyNote.h"


MattyGroupBox::MattyGroupBox()
{
    buildFrame();
}

//void MattyGroupBox::fillFrame(MattyNote & ThisNote)
//{
    //NoteTitleLabel->setText(ThisNote.getTitle());
    //NoteTypeLabel->setText(ThisNote.getType());
    //NoteTextLabel->setText(ThisNote.getText());    
//}

void MattyGroupBox::buildFrame()
{
    // тут очень много того, из-за чего потребовалось наследовать класс
    // добавление элементов Qt

}

MattyGroupBox::~MattyGroupBox()
{
    delete NoteTitleLabel;
    delete NoteTypeLabel;
    delete NoteCrTimeAndDateLabel;
    delete NoteEventTimeAndDateLabel;
    delete NoteTextLabel;
    delete horizontalSpacer_1;
    delete horizontalSpacer_2;
    delete verticalSpacer;
    delete editNoteButton;
    delete deleteNoteButton;
    delete horizontalLayout_1;
    delete horizontalLayout_2;
    delete verticalLayout;
    delete gridLayout;
}

如果取消注释该方法,则会出现错误:

Error   C2511   'void MattyGroupBox::fillFrame(MattyNote &)': overloaded member function not found in 'MattyGroupBox'
Error   C2061   syntax error: identifier 'MattyNote'

MattyNote.h

#ifndef MATTYNOTE_H
#define MATTYNOTE_H

#include "MattyTime.h"

class MattyNote
{
public:
    MattyNote();
    ~MattyNote();
    void setTitle(const QString & Title);
    void setType(const QString & TypeName);
    void setType(int TypeId);
    void setText(const QString & Text);
    void setEventTime(const QString & EventTime); // Warning! Input format must be: 00:00
    void setEventDate(const QString & EventDate); // Warning! Input format must be: 00.00.0000
    QString getTitle();
    QString getType();
    QString getText();
    QString getEventTime(); // Format: 00:00
    QString getEventDate(); // Format: 00.00.0000
    QString getCrTime(); // Format: 00:00
    QString getCrDate(); // Format: 00.00.0000
    int getTypeId();
    TimeAndDate* getEventTimeAndDate(); // Returns a pointer to TimeAndDate structure containing ints
    TimeAndDate* getCrTimeAndDate(); // Returns a pointer to the TimeAndDate structure containing ints
private:
    int NoteTypeId;
    QString NoteTitle;
    QString NoteType;
    QString NoteText;
    QString NoteEventTime; // Format: 00:00
    QString NoteEventDate; // Format: 00.00.0000
    MattyTime* EventTimeAndDate;  // Any unspecified part equals -1
    MattyTime* CrTimeAndDate;  // Automaticly set in constructor of MattyNote
};

#endif // MATTYNOTE_H

MattyNote.cpp

#include "stdafx.h"
#include "MattyNote.h"
#include "Constants.h"
#include "DbManager.h"

MattyNote::MattyNote()
{
    EventTimeAndDate = new MattyTime();
    EventTimeAndDate->setUserTimeAndDateNull();
    CrTimeAndDate = new MattyTime();
    MattyTime::updateCurrTime();
    CrTimeAndDate->UserTimeAndDate = MattyTime::CurrTime;
}

MattyNote::~MattyNote()
{
    delete EventTimeAndDate;
    delete CrTimeAndDate;
}

void MattyNote::setTitle(const QString & Title)
{
    NoteTitle = Title;
}

void MattyNote::setType(const QString & TypeName)
{
    DbManager* MattyNotesDbManager = new DbManager("MattyNotes.sqlite");
    NoteTypeId = MattyNotesDbManager->getTypeId(TypeName);
    NoteType = TypeName;
    delete MattyNotesDbManager;
}

void MattyNote::setType(int TypeId)
{
    DbManager* MattyNotesDbManager = new DbManager("MattyNotes.sqlite");
    NoteType = MattyNotesDbManager->getTypeName(TypeId);
    NoteTypeId = TypeId;
    delete MattyNotesDbManager;
}

void MattyNote::setText(const QString & Text)
{
    NoteText = Text;
}

void MattyNote::setEventTime(const QString & EventTime)
{
    if (EventTime.length() == Constants::TimeQStringLength && EventTime[2] == Constants::TimeSeparator)
    {
        NoteEventTime = EventTime;
        QStringList TimeTemp = EventTime.split(Constants::TimeSeparator);
        EventTimeAndDate->UserTimeAndDate->hour = TimeTemp[0].toInt();
        EventTimeAndDate->UserTimeAndDate->minute = TimeTemp[1].toInt();
        EventTimeAndDate->UserTimeAndDate->second = 0;
    }
}

void MattyNote::setEventDate(const QString & EventDate)
{
    if (EventDate.length() == Constants::DateQStringLength &&
        EventDate[Constants::PositionOfFirstDateSeparator] == Constants::DateSeparator
        && EventDate[Constants::PositionOfSecondDateSeparator] == Constants::DateSeparator)
    {
        NoteEventDate = EventDate;
        QStringList DateTemp = EventDate.split(Constants::DateSeparator);
        EventTimeAndDate->UserTimeAndDate->day = DateTemp[0].toInt();
        EventTimeAndDate->UserTimeAndDate->month = DateTemp[1].toInt();
        EventTimeAndDate->UserTimeAndDate->year = DateTemp[2].toInt();
        EventTimeAndDate->setUserDayOfWeek();
    }
}

QString MattyNote::getTitle()
{
    return NoteTitle;
}

QString MattyNote::getType()
{
    return NoteType;
}

QString MattyNote::getText()
{
    return NoteText;
}

QString MattyNote::getEventTime()
{
    return NoteEventTime;
}

QString MattyNote::getEventDate()
{
    return NoteEventDate;
}

QString MattyNote::getCrTime()
{
    return CrTimeAndDate->PrintUserTime();
}

QString MattyNote::getCrDate()
{
    return CrTimeAndDate->PrintUserDate();
}

int MattyNote::getTypeId()
{
    return NoteTypeId;
}

TimeAndDate * MattyNote::getEventTimeAndDate()
{
    return EventTimeAndDate->UserTimeAndDate;
}

TimeAndDate * MattyNote::getCrTimeAndDate()
{
    return CrTimeAndDate->UserTimeAndDate;
}

stdafx.h 根本不包含标头,Constants.h、DbManager.h、MattyTime.h 和它们的 cpp 也不会发送到任何地方。

实际上,这里可能有什么问题?一般来说,该项目有 10 个头文件和代码文件,如果您需要其他内容,我会发布。

c++
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Vlad from Moscow
    2020-10-30T07:26:05Z2020-10-30T07:26:05Z

    显然,问题是在声明类时,QGroupBox编译器看不到名称声明MattyNote。

    所以要么在 headerMattyNote.h中包含 header MattyGroupBox.h,要么在MattyGroupBox.h类声明的 header 中,写

    void fillFrame( class MattyNote & ThisNote);
                    ^^^^
    

    或者在类声明之前写

    class MattyNote;
    
    • 4

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    如何停止编写糟糕的代码?

    • 3 个回答
  • Marko Smith

    onCreateView 方法重构

    • 1 个回答
  • Marko Smith

    通用还是非通用

    • 2 个回答
  • Marko Smith

    如何访问 jQuery 中的列

    • 1 个回答
  • Marko Smith

    *.tga 文件的组重命名(3620 个)

    • 1 个回答
  • Marko Smith

    内存分配列表C#

    • 1 个回答
  • Marko Smith

    常规赛适度贪婪

    • 1 个回答
  • Marko Smith

    如何制作自己的自动完成/自动更正?

    • 1 个回答
  • Marko Smith

    选择斐波那契数列

    • 2 个回答
  • Marko Smith

    所有 API 版本中的通用权限代码

    • 2 个回答
  • Martin Hope
    jfs *(星号)和 ** 双星号在 Python 中是什么意思? 2020-11-23 05:07:40 +0000 UTC
  • Martin Hope
    hwak 哪个孩子调用了父母的静态方法?还是不可能完成的任务? 2020-11-18 16:30:55 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    Arch ArrayList 与 LinkedList 的区别? 2020-09-20 02:42:49 +0000 UTC
  • Martin Hope
    iluxa1810 哪个更正确使用:if () 或 try-catch? 2020-08-23 18:56:13 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5