PDA

View Full Version : Multi-Window Application



bernard
29th October 2012, 05:04
Hi!

I've been tinkering around with this for a couple days, and errors have come and gone, but still I haven't successfully compiled this. I figure I'm missing something very simple, but haven't tracked it down yet.

The Scenario:
I have a main window that works just fine, a simulator. From this I've connected a push button to a function in a source file, MUstarter.cpp, that will act as a copy of main to start the other window. The reason: I want to keep the new window's code isolated so I can deploy it as a separate project later. I have a feeling the main issue is with the header file for the new window, but I'm not sure.

The code:
MUstarter.cpp -> called from the generator window, should act how main usually does.


#include <QtGui/QApplication>

#include "MobileUnit.h"
#include "ui_MobileUnit.h"

void MUStarter()
{
MobileUnit MU;
MU.show();
MU.setWindowTitle(
QApplication::translate("MobileUnit", "Mobile Unit"));
}

MobileUnit.cpp -> define any widget functionality of the new ui.


#include "MobileUnit.h"
#include "ui_MobileUnit.h"

#include <QWidget>

MobileUnit::MobileUnit(QWidget *parent) :
QWidget(parent),
MU(new Mu::MobileUnit)
{
MU->setupUi(this);
}

MobileUnit::~MobileUnit()
{
delete MU;
}

MobileUnit.h -> class definitions


#ifndef MOBILEUNIT_H
#define MOBILEUNIT_H

#include <QWidget>

namespace Mu {
class MobileUnit;
}

class MobileUnit: public QWidget
{
Q_OBJECT

public:
explicit MobileUnit(QWidget *parent = 0);
~MobileUnit();

private:
Mu::MobileUnit *MU;
// void MUStarter();
};

#endif // MOBILEUNIT_H

Thanks in advance for any help!

wysota
29th October 2012, 07:20
What errors are you getting?

bernard
29th October 2012, 16:24
Sorry, that would probably help! :)

../SRLmainApp/MobileUnit/MobileUnit.cpp: In constructor 'MobileUnit::MobileUnit(QWidget*)':
../SRLmainApp/MobileUnit/MobileUnit.cpp:9:16: error: invalid use of incomplete type 'struct Mu::MobileUnit'
../SRLmainApp/MobileUnit/MobileUnit.h:7:7: error: forward declaration of 'struct Mu::MobileUnit'
../SRLmainApp/MobileUnit/MobileUnit.cpp:11:7: error: invalid use of incomplete type 'struct Mu::MobileUnit'
../SRLmainApp/MobileUnit/MobileUnit.h:7:7: error: forward declaration of 'struct Mu::MobileUnit'
../SRLmainApp/MobileUnit/MobileUnit.cpp: In destructor 'virtual MobileUnit::~MobileUnit()':
../SRLmainApp/MobileUnit/MobileUnit.cpp:16:12: warning: possible problem detected in invocation of delete operator: [enabled by default]
../SRLmainApp/MobileUnit/MobileUnit.cpp:16:12: warning: invalid use of incomplete type 'struct Mu::MobileUnit' [enabled by default]
../SRLmainApp/MobileUnit/MobileUnit.h:7:7: warning: forward declaration of 'struct Mu::MobileUnit' [enabled by default]
../SRLmainApp/MobileUnit/MobileUnit.cpp:16:12: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined
make: *** [MobileUnit.o] Error 1

This is about the worst it's been, but regardless, I still don't know why I'd be getting all these errors.

wysota
29th October 2012, 17:43
Which file defines the Mu::MobileUnit class? Shouldn't it be Ui::MobileUnit?

bernard
29th October 2012, 20:59
Maybe I'm wrong - I thought to differentiate between the two sources I should define a new namespace for this gui. The 'Mu' namespace was defined in the header file, 'MobileUnit.h'.

Should I stick with the Ui namespace, or does it matter? I assumed it would be arbitrary, but maybe the .ui forms are closely linked to that Ui namespace... ?

wysota
29th October 2012, 21:27
Maybe I'm wrong - I thought to differentiate between the two sources I should define a new namespace for this gui. The 'Mu' namespace was defined in the header file, 'MobileUnit.h'.
You defined the namespace but you didn't put the MobileUnit class in it. There is a difference between MobileUnit and MU::MobileUnit, they are two totally separate entities.

bernard
30th October 2012, 03:32
That solved it! Another problem I was having was that using Mu instead of Ui caused some contradictions with the Ui namespace in ui_MobileUnit.h built elsewhere (or at least that's my guess).

Thanks for the help!