Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用QT Creator/c++;_C++_List_Qt_Qt Creator - Fatal编程技术网

C++ 使用QT Creator/c++;

C++ 使用QT Creator/c++;,c++,list,qt,qt-creator,C++,List,Qt,Qt Creator,我如何制作一个QList,使得这个列表可以包含来自多个类的信息(这些类由两个映射容器操作) 这是我的四门课: 课堂讲授: class Veranstaltung { private: QMap<QString, LV >myLV; public: Veranstaltung() {} void listLV(QTextStream& out) const; ... }; #endif //

我如何制作一个QList,使得这个列表可以包含来自多个类的信息(这些类由两个映射容器操作)

这是我的四门课:

课堂讲授:

  class Veranstaltung
    {
    private:
       QMap<QString, LV >myLV; 
    public:
    Veranstaltung() {}
    void listLV(QTextStream& out) const; 
    ...
   };

    #endif // 
class-Veranstaltung
{
私人:
QMapmyLV;
公众:
Veranstaltung(){}
void listLV(QTextStream&out)const;
...
};
#endif//
教授级

    LIST_H

     class ProfessurList
    {
    private:
        QMap<QString, Professur> myProfessuren; 
    public:
        ProfessurList() {} //kann man weglassen
        void addProf(QTextStream& in,QTextStream& out);
        void listProf(QTextStream& out) const; //Warum const?
       ...
    };

    #endif // PROFLIST_H
列表
班级教授
{
私人:
QMap-myProfessuren;
公众:
教授(){}//kann man weglassen
void addProf(QTextStream&in、QTextStream&out);
void listProf(QTextStream&out)const;//Warum const?
...
};
#endif//PROFLIST\u H
讲座的另一个课程,其中定义了私人和公共:

#ifndef LV_H
#define LV_H

class LV
{
private:
    QString myNummer;
    QString myBezeichnung;
    QString myTyp;
public:
    LV(const QString& nummer, const QString& bezeichnung, const QString& typ):
        myNummer(nummer), myBezeichnung(bezeichnung), myTyp(typ)

    {}
    QString nummer() const { return myNummer;}

    ...
};
QTextStream& operator<<(QTextStream& out, const LV& l); 

#endif // LV_H
  #ifndef PROF_H
    #define PROF_H


    class Professur
    {
    private:
    QString myKuerzel;
    QString myName;
    QString myLehrstuhlinhaber;
    public:
    Professur(const QString& kuerzel, const QString& name, const QString& lehrstuhlinhaber):
        myKuerzel(kuerzel), myName(name), myLehrstuhlinhaber(lehrstuhlinhaber)
    {}

   ...
    };
    QTextStream& operator<<(QTextStream& out, const Professur& pr);

    #endif // PROF_H
\ifndef LV\u H
#定义LV_H
LV类
{
私人:
QString-mynumer;
QString mybezeichung;
QString-myTyp;
公众:
低压(恒压串和数字、恒压串和Bezeichung、恒压串和典型):
myNummer(nummer)、MyBezeichung(Bezeichung)、myTyp(typ)
{}
QString numer()常量{return mynumer;}
...
};

QTextStream&operator您不能简单地用X对象创建struct吗?比如:

Struct ProfessorsAndLecturs
{
   Veranstaltung v;
   LEctures l;
   ...
};
ProfessorsAndLecturs pal;
pal.v = ...;
pal.l = ...;

QList<ProfessorsAndLecturs> list;
list.append(pal);

如果这是你要的。

我不确定你要的是什么。你能详细说明你想做什么,以及它与你所包含的代码片段的关系吗?你能澄清一下你到底需要在QList中存储什么吗?为了存储异构数据,请使用
QVariant
,特别是-
QVariantList
。谢谢@kajojeq,但我必须对类这样做,我为教授和讲座(3和4)定义了类,然后制作了两个地图容器,元素应该在其中操作(并保存到QList的cpp文件中的文本文件),我用1和2完成了这项工作,将额外的类定义为QList,我还需要做的是:编写讲座,这是一个教授的职位,我不知道如何才能获得这两个班级的信息,以及在哪里:在一个新的文本文件(cpp)和QList列表中;或者某些东西必须在一个.h文件中定义。谢谢@kajojeq,但我必须用类来定义,我为教授和讲座(3和4)定义了类,然后制作了两个地图容器,元素应该在其中操作(并保存到QList的cpp文件中的文本文件),我用1和2完成了这项工作,将额外的类定义为QList,我仍然要做的是:写讲座,在其中一个教授职位上,我不知道如何获取这两个类的信息,以及在哪里:在一个新的文本文件(cpp)中,或者必须在其中一个.h中定义什么files@DianaPapukchieva很难理解你想要什么,但是我试着:也许你需要一个包含这个proffesures.h文件的讲座列表,所以在proffesures.h文件中添加
#包括“LV.h”
稍后
QList讲师列表然后,当您添加proffesure时,将讲座也添加到此列表中,现在您有了对象proffesure及其拥有的讲座列表。现在object有:object.讲师列表;如果你写下你需要做的全部任务,可能会更容易。我会在“LV.h”中尝试,非常感谢,我不能写下全部任务,因为这是一个家庭作业,我必须独自解决,还有一件事谢谢。)
list.at(0).l;
etc.