Reply
Thread Tools
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#1
I remember having this problem before with the qt creator and I have no idea what I did back then to make it work. Now a month later I the problem have come back...

What I want to do is creating an instance of ListWindow in the HistoryWindow.

Yesterday there was no problem what so ever. If I remove the declaration of listwindow in historywindow.h I have the same problem with many other windows... Please help me!

History.h
Code:
#ifndef HISTORYWINDOW_H
#define HISTORYWINDOW_H

#include <QMainWindow>
#include "listwindow.h"
#include "xml.h"

class HistoryWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit HistoryWindow(QWidget *parent = 0);

private:
    ListWindow *lw;
    XML *xml;

};

#endif // HISTORYWINDOW_H
list.h
Code:
#ifndef LISTWINDOW_H
#define LISTWINDOW_H

#include <QMainWindow>
#include <QtGui>
#include "infowindow.h"
#include "infomotionwindow.h"
#include "xml.h"

class ListWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit ListWindow(QWidget *parent = 0);
    void loadExercises(QString group);
    void loadDate(QString date);

signals:

public slots:

private:
    XML *xml;
    InfoWindow *iw;
    InfoMotionWindow *imw;
    HistoryWindow *hw;
    SettingsWindow *sw;
    NewExerciseWindow *nw;
    NewProgramWindow *npw;

    void createActions();
    void createMenu();


    QAction *historyAction;
    QAction *settingsAction;
    QAction *newExerciseAction;
    QAction *newProgramAction;
    QAction *exportAction;

    QListView *lstExercises;
    QStandardItemModel *model;

    QList < QList <QString> > exercises;

    QString group;

private slots:
    void showInfo(QModelIndex index);
    void showHistory();
    void showSettings();
    void showNewExercise();
    void showNewProgram();
    void deleteItem();
    void editItem();
    void showContextMenuForWidget(const QPoint &pos);
};

#endif // LISTWINDOW_H
and finally list.cpp
Code:
#include "listwindow.h"
#include <QtGui>

ListWindow::ListWindow(QWidget *parent) :
    QMainWindow(parent)
{
    setAttribute(Qt::WA_Maemo5StackedWindow);

    iw = new InfoWindow(this);
    iw->hide();
    imw = new InfoMotionWindow(this);
    imw->hide();
    hw = new HistoryWindow(this);
    hw->hide();
    sw = new SettingsWindow(this);
    sw->hide();
    nw = new NewExerciseWindow(this);
    nw->hide();
    npw = new NewProgramWindow(this);
    npw->hide();
    xml = new XML();

    model = new QStandardItemModel(this);

    lstExercises = new QListView();
    lstExercises->setModel(model);

    connect(lstExercises,SIGNAL(clicked(QModelIndex)),this,SLOT(showInfo(QModelIndex)));
    lstExercises->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(lstExercises, SIGNAL(customContextMenuRequested(const QPoint &)),SLOT(showContextMenuForWidget(const QPoint &)));

    createActions();
    createMenu();

    setCentralWidget(lstExercises);
}

void ListWindow::loadExercises(QString grp)
{
    QList <QString> list;
    group = grp;
    list = xml->openGroup(grp);

    model->clear();
    lstExercises->setSelectionMode(QListView::SingleSelection);
    if(list.isEmpty())
    {
        model->appendRow(new QStandardItem ("No exercises"));
        lstExercises->setSelectionMode(QListView::NoSelection);
        return;
    }

    while(!list.isEmpty())
    {
        model->appendRow(new QStandardItem(list.takeFirst()));
    }
    model->sort(0);
}

void ListWindow::loadDate(QString date)
{
    QList <QString> tmp;
    QString name, grp, reps, var;
    setWindowTitle(date);
    model->clear();
    exercises = xml->getHistoryByDate(date);

    while(!exercises.isEmpty())
    {
        tmp = exercises.takeFirst();
        name = tmp.takeFirst();
        grp = tmp.takeFirst();
        var = tmp.takeFirst();
        reps = tmp.takeFirst();

        if(grp != "Cardio")
            model->appendRow(new QStandardItem(grp + "/" + name + ": " + var + "Kg - " + reps + " reps"));
        else
            model->appendRow(new QStandardItem(grp + "/" + name + ": " + var + "Km" + " - " + reps));
    }
}

void ListWindow::showInfo(QModelIndex index)
{
    setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
    if(index.data().toString() == "No exercises")
        return;
    if(group !=  "Cardio")
    {
        iw->loadExercise(index.data().toString());
        iw->show();
    }
    else
    {
        imw->loadExercise(index.data().toString());
        imw->show();
    }
}

void ListWindow::showHistory()
{
    hw->show();
}

void ListWindow::showSettings()
{
    sw->load();
    sw->show();
}

void ListWindow::showNewExercise()
{
    nw->show();
}

void ListWindow::showNewProgram()
{
    npw->show();
}

void ListWindow::createMenu()
{
    QMenu *menu;
    menu = menuBar()->addMenu(tr("&Menu"));
    menu->addAction(historyAction);
    menu->addAction(settingsAction);
    menu->addAction(newExerciseAction);
    menu->addAction(newProgramAction);
    menu->addAction(exportAction);
}

void ListWindow::createActions()
{
    historyAction = new QAction("History",this);
    settingsAction = new QAction("Settings",this);
    newExerciseAction = new QAction("New Exercise",this);
    newProgramAction = new QAction("New program",this);
    exportAction = new QAction("Export exercises",this);


    connect(historyAction, SIGNAL(triggered()), this, SLOT(showHistory()));
    connect(settingsAction, SIGNAL(triggered()), this, SLOT(showSettings()));
    connect(newExerciseAction, SIGNAL(triggered()), this, SLOT(showNewExercise()));
    connect(newProgramAction, SIGNAL(triggered()), this, SLOT(showNewProgram()));
}

void ListWindow::showContextMenuForWidget(const QPoint &pos)
{

    QMenu contextMenu(this);
    QAction *editItemAction = new QAction("Edit", this);
    QAction *deleteItemAction = new QAction("Remove", this);

    connect(editItemAction, SIGNAL(triggered()), this, SLOT(editItem()));
    connect(deleteItemAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
    contextMenu.addAction(editItemAction);
    contextMenu.addAction(deleteItemAction);
    contextMenu.exec(mapToGlobal(pos));
}

void ListWindow::deleteItem()
{
    QString str;

    str = lstExercises->currentIndex().data().toString();

    for(int i = 0; i < model->rowCount();i++)
    {
        if(model->index(i,0).data().toString() == str)
            model->removeRow(i);
    }

    xml->removeElement(str);
}

void ListWindow::editItem()
{
    QString str;
    QList <QString> list;
    str = lstExercises->currentIndex().data().toString();

    list = xml->openEx(str);
    nw->load(list.takeFirst(),list.takeFirst(),list.takeFirst(),list.takeFirst());
    nw->show();
}
 
Posts: 353 | Thanked: 263 times | Joined on Dec 2009 @ Finland
#2
Could you copy the exact error message here?
__________________
My Maemo5 projects:
mSpede - Speed testing game | Them Bloody Ducks - 2D duck hunting game | Maetronome - A simple metronome app | CuteMPC - MPD client
 

The Following 2 Users Say Thank You to TNiga For This Useful Post:
Posts: 415 | Thanked: 732 times | Joined on Jan 2009 @ Finland
#3
most likely you are missing headers/forward declarations for some classes that you're using in your classes.

The error message should contain the class you're trying to use without telling the compiler what it is

Last edited by timoph; 2010-06-02 at 12:53.
 

The Following User Says Thank You to timoph For This Useful Post:
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#4
slim/usr/include -I/usr/include -IC:/NokiaQtSDK/Maemo/4.6.2/sysroots/fremantle-arm-sysroot-1014-slim/usr/include/phonon_compat -I. -o main.o main.cpp
In file included from infowindow.h:6,
from listwindow.h:6,
from weightwindow.h:6,
from startwindow.h:6,
from main.cpp:2:
historywindow.h:15: error: ISO C++ forbids declaration of 'ListWindow' with no type
historywindow.h:15: error: expected ';' before '*' token
make: Leaving directory `/c/NokiaQtSDK/QtCreator/bin/qexercise'
make: *** [main.o] Error 1
Exited with code 2.
Error while building project qexercise (target: Maemo)
When executing build step 'Make'

If I remove #include "listwindow.h" it says the same thing as before. If I move ListWindow *lw to the cpp file the error disapears, at least it was like that the last time...
 
Posts: 13 | Thanked: 5 times | Joined on Oct 2009
#5
historywindow.h doesn't know where the ListWindow header file is thus it doesn't recognize ListWindow as a type.

Check if in the .pro file contains all necessary file paths in SOURCES and HEADERS

remember to run qmake before you actually try to compile it.

Hope it helped.
 

The Following User Says Thank You to skomialek For This Useful Post:
Posts: 67 | Thanked: 28 times | Joined on Oct 2009 @ Switzerland
#6
Your problem seems to be that you have a circular dependency: ListWindow contains a pointer to a HistoryWindow and vice versa. You have to add a forward declaration to listwindow.h and historywindow.h. (see here for details)
 

The Following 3 Users Say Thank You to gidoca For This Useful Post:
Posts: 15 | Thanked: 4 times | Joined on Mar 2010 @ Germany
#7
I think you changed the name of your files did you? when quoting you named them list.h etc. the includes and also the error message say listwindow.h.
Do you perhaps have a copy of the old file in your dir? Thus the compiler not seeing the file you are changing?

Another nice problem that can come from copying pasting is the use of the same preprocessor symbol (I mean in the first two and the last line of a header file e.g. LISTWINDOW_H). If you use the SAME symbol name in two headers this can also lead to confusing errors.

In any way: you should use as least includes in a header file as possible in order to reduce compilation time.
In file history.h you do no need to include listwindow.h.
A simple forward declaration is sufficient: add "class ListWindow;" before the declaration of "class HistoryWindow ..." and remove the '#include "ListWindow.h"'.

Hope this helps.
best regards eichhofener.

PS: Share your program with us, when it is ready :-)
 

The Following User Says Thank You to oberndorfer For This Useful Post:
Posts: 15 | Thanked: 4 times | Joined on Mar 2010 @ Germany
#8
Originally Posted by gidoca View Post
Your problem seems to be that you have a circular dependency: ListWindow contains a pointer to a HistoryWindow and vice versa. You have to add a forward declaration to listwindow.h and historywindow.h. (see here for details)
oh yes. did not see this.
 
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#9
It was the circular problem, never heard of that before. Maybe it do not exist in java? Well now I know how to solve this the next time, thanks alot!

And about sharing the program, I will probebly upload the code here so someone else can do it. I have tried many hours so I have given it up
 

The Following User Says Thank You to Lullen For This Useful Post:
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#10
Languages like C and C++ need to compute the amount of storage that is needed for different types. To do this, the types have to be defined, in some way, to be able to either know, make a guess and fix it later or leave a marker saying that this will be resolved later.

The typical C example is the following:
Code:
struct list {
  int length;
  struct item *first;
};

struct item {
  void *data;
  struct item *next;
};
This will not compile without a forward declaration of
Code:
struct item;
that tells the compiler that there is a symbol named item that is a struct but that it will be defined later so just keep parsing and it will work out.
 

The Following User Says Thank You to Joorin For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 14:42.