Seite 1 von 1
Header Crosslink
Verfasst: 1. Mai 2007 09:03
von Frostie
Hallo Kollegen,
hab mal wieder ein kleines Problem, hab hier schon gesucht aber nix passendes gefunden.
So,
ich habe ein MainWindow.h und cpp und eine functions.h und cpp.
Ich habe jetzt die MainWindow.h in der functions.h includiert, da ich
in den Funktionen handles auf WainWindow brauche.
Nun wollte ich in der MainWindow.h auch die functions.h includieren, da
ich ja die Funktionen in der MainWindow benutzen will.
Doch leider meldet er dann einen Fehler, das er auf einmal die MainWindow im functions.h nicht mehr kennt!?!?
Bin total verwirrt, hat hierfür jemand eine Erklärung??
Danke
Gruß
Matthias
Verfasst: 1. Mai 2007 09:47
von Christian81
Stichwort 'forward declarations'
class MainWindow;
Verfasst: 1. Mai 2007 10:01
von Frostie
Ok,
danke erstmal, dass hatte ich noch nicht gewußt.
Also wenn ich dann
class MainWindow;
in den functions.h rein setze, kompiliert er auch ohne Probleme,
doch wenn ich dann weitermache und mit
functions func;
ein Objekt in der MainWindow.h erstellen will, bring er mir wieder Fehler, dass das nicht geht:
Error46 error C2146: syntax error : missing ';' before identifier 'func'
Kennst Da da noch eine Lösung?
Danke
Gruß
Matthias
Verfasst: 1. Mai 2007 10:19
von Christian81
Damit kann man nur Klassen und Strukturen deklarieren.
Was anderes hat auch keinen Sinn und ist nicht nötig - ich würde mal die Header etwas aufräumen...
Verfasst: 1. Mai 2007 10:22
von Frostie
Ähm,
hab ich jetzt was nicht mitbekommen,
functions ist doch ne Klasse.
????
Gruß
Matthias
Verfasst: 1. Mai 2007 10:24
von Christian81
Aber dann müsste es doch nur
'class functions' heissen und fertig.
Verfasst: 1. Mai 2007 10:27
von Frostie
Code: Alles auswählen
class MainWindow : public QMainWindow, protected Ui_MainWindow
{
Q_OBJECT
public:
functions func;
QString path;
QString path_log;
Also das oben geht ned!
Und soll ich das jetzt so machen:
Code: Alles auswählen
class MainWindow : public QMainWindow, protected Ui_MainWindow
{
Q_OBJECT
public:
class functions;
QString path;
QString path_log;
Das macht doch keinen Sinn, oder?
Hier mal alle Files im Überblick:
MainWindow.h
Code: Alles auswählen
#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_
#include "ui_MainWindow.h"
#include "functions.h"
#include <qsqldatabase.h>
#include <QDateTime>
#include <QHttp>
#include <QFtp>
#include <qfile.h>
class MainWindow : public QMainWindow, protected Ui_MainWindow
{
Q_OBJECT
public:
functions func;
MainWindow.cpp
Code: Alles auswählen
#include <QApplication>
#include <QMessageBox>
#include <QDialog>
#include "MainWindow.h"
#include "Dialog.h"
#include "functions.h"
#include "top_window.h"
#include "time_insert.h"
#include "user_insert.h"
#include "help.h"
#include "about.h"
#include "status_insert.h"
#include "project_insert.h"
#include "owner_insert.h"
#include "owner_edit.h"
#include "project_edit.h"
#include "project_delete.h"
#include "user_edit.h"
#include "profile_insert.h"
#include "profile_edit.h"
#include "profile_delete.h"
#include "user_delete.h"
#include "first_start.h"
#include "time_out.h"
#include <QListView>
#include <qsqldatabase.h>
#include <qsqltablemodel.h>
#include <qsqlerror.h>
#include <qsqlquery.h>
#include <qsqlfield.h>
#include <qsqltablemodel.h>
#include <qsqlrelationaltablemodel.h>
#include <qsqlrelationaldelegate.h>
#include <qsqlrecord.h>
#include <QTableWidget>
#include <QHeaderView>
#include <qfile.h>
#include <qtextstream.h>
#include <QTimer>
#include <QRgb>
#include <QColor>
#include <QThread>
#include <QProcess>
#include "thread.h"
#include "smtp.h"
#include <QSysInfo>
#include <QDir>
MainWindow::MainWindow(QWidget* parent /* = 0 */, Qt::WindowFlags flags /* = 0 */)
: QMainWindow(parent, flags)
{
..
func.funktion...
functions.h
Code: Alles auswählen
#ifndef FUNCTIONS_H_
#define FUNCTIONS_H_
#include "MainWindow.h"
#include <iostream>
#include <qtimer.h>
#include <qvariant.h>
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
#include <QDialog>
#include <QHBoxLayout>
#include <QLabel>
#include <QListView>
#include <QListWidget>
#include <QPushButton>
#include <QSpacerItem>
#include <QTableView>
#include <QTableWidget>
#include <QTreeWidget>
#include <QWidget>
#include <qsqldatabase.h>
#include <qsqlerror.h>
#include <qsqlquery.h>
#include <qsqltablemodel.h>
#include <qsqlrelationaltablemodel.h>
#include <qsqlrelationaldelegate.h>
#include <qsqlrecord.h>
#include <QTimerEvent>
class MainWindow;
class functions
{
//Q_OBJECT
public:
functions.cpp
Code: Alles auswählen
#include "functions.h"
#include <QMessageBox>
#include <qtimer.h>
#include <qdatetime.h>
#include <QDialog>
#include <qfile.h>
#include <qtextstream.h>
#include <QApplication>
#include <qprocess.h>
#include <qsqldatabase.h>
#include <qsqlerror.h>
#include <qsqlquery.h>
#include <qsqltablemodel.h>
#include <qsqlrelationaltablemodel.h>
#include <qsqlrelationaldelegate.h>
#include <qsqlrecord.h>
#include <QTimerEvent>
#include <QProcess>
#include "qtmd5.h"
#include "MainWindow.h"
#include "first_start.h"
#include <QDir>
#include <QSettings>
#define CONNECT_ERROR "Fehler bei der Verbindung!"
#define CONNECT_LOCAL_HOST "localhost"
#define CONNECT_LOCAL_DB "project_database"
functions::functions()
{
Verfasst: 1. Mai 2007 10:36
von Christian81
Also die grosse Frage - was ist eine Deklaration und was eine Definition...
Code: Alles auswählen
class functions;
class MainWindow : public QMainWindow, protected Ui_MainWindow
{
Q_OBJECT
public:
functions *func;
QString path;
QString path_log;
...
Dies geht aber nur wenn func ein Pointer ist. Ist er keiner, bleibt Dir nichts anderes übrig als den Header in dem functions deklariert ist, zu inkludieren und in diesem dann eine Vorwärtsdeklaration einzubauen.
Verfasst: 1. Mai 2007 16:02
von Frostie
Danke,
das wars.
Gruß
Matthias