Unsolved Weird behavior of QList<T>
-
@advtaco Are you sure you really have roomCount entries in the list? You should check that first.
-
-
@advtaco said in Weird behavior of QList<T>:
#ifndef KROOM_H
#define KROOM_H#include <QList>
#include <QString>
#include <kswitch.h>
#include <kblind.h>class kRoom
{
public:
kRoom(QString name);
QList<kSwitch> switches;
QList<kBlind> blinds;
QString name;
void addSwitch(kSwitch newSwitch);
void removeSwitch(int remSwitch);
void addBlind(kBlind newBlind);
void removeBlind(int remBlind);
};When I used class in other classes I had a problem with the following:
like this> #include <QList> > #include <QString> > #include <kswitch.h> > #include <kblind.h> class kSwtich; class kBlind;
Could this be a problem anyway?
-
@Taz742 Sory, I don't follow: what problem do you mean?
-
@advtaco Not related to your question: may I ask you why you use printf C function? It makes your code more complex as you need to get char* out of QString. Why not use qDebug for debugging or std::cout for regular std out - you're using C++ not C :-)
-
-
I'm speechless... I can only thing of something weird going on in
building
ok, let's try with an alternative.
replacefor (int i = 0; i < roomCount; i++) { printf(QString::number(i).toLatin1().data()); printf(QString("Room #" + QString::number(i) + ", " + building->rooms.at(i).name + "\n\r").toLatin1().data()); printf(QString("Switches: " + QString::number(building->rooms.at(i).switches.count()) + "\n\r").toLatin1().data()); printf(QString("Blinds: " + QString::number(building->rooms.at(i).blinds.count()) + "\n\r").toLatin1().data()); printf("+---------------------------+\n\r"); }
with
foreach(const kRoom& singleRoom, building->rooms){ qDebug() << singleRoom.name; }
-
@Taz742 Well, you need to have the class definition somewhere, a forward declaration isn't a definition.
-
@jsulm said in Weird behavior of QList<T>:
@advtaco Not related to your question: may I ask you why you use printf C function? It makes your code more complex as you need to get char* out of QString. Why not use qDebug for debugging or std::cout for regular std out - you're using C++ not C :-)
For more infos on this front, see https://stackoverflow.com/questions/3886105/how-to-print-to-console-when-using-qt
-
-
@advtaco
The problem was qDebug () or foreach (const kRoom & singleRoom, building-> rooms) ?