[Solved] Am i being stupid here?
-
Hi all bearing in mind i have been on a bit of a program marathon so i apologies if this is a simple answer (c++ is a fairly new language to me).
I have a class called OpenShots that is a QDialogue, and another class called main window that is a QMainWindow. I have include the header for Open shots in my mainwindow header and I am attempting to create an instance of that object in my mainwindow.h called opshots (See code bellow).
However whenever i try to compile this i get an error "missing ';' before identifier 'opshots'".Any ideas why?
@#include "OpenShots.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
~MainWindow();
private:
Ui::MainWindowClass ui;
void createLogonPage();
OpenShots opshots;};
@ -
The semantics of your code appear ok, however this is not the way you should do it, in the header declare a "OpenShots *opshots" and in the cpp create the opshots obejct with "new OpenShots"
-
Yes i did try that one as well but it returned the same error it's not because i'm trying to define a QDalog object inside a QMainWindow header file is it, only if i define it in one of the internal methods or the constructor it works fine?
-
Does your OpenShots class have a ";" at the end of the class definition?
@
class OpenShots ... {
...
}; <-- here
@ -
};
#endif // OPENSHOTS_H
yep sure did and the constructor for that class is OpenShots(QWidget *parent = 0);
-
Hi,
I'm just guessing:
Do you have?
@
#ifndef OPENSHOTS_H
#define OPENSHOTS_H
@
on the top?the <something.h> and <something> error
The constructor implemetation in cpp:
@
#include "OpenShots.h"
OpenShots::OpenShots(QWidget *parent) : QDialog(parent)
{
}
@Also, i see you're using the:
@Ui::MainWindowClass ui;@
There is nothing between line 1 and 3?
@
#include "OpenShots.h"class MainWindow : public QMainWindow
@
It should be in case you're not using a *ui.
I'm wondering from where you know something about
@Ui::MainWindowClass@My favourite approach:
If youre not including this here you should have also a forward declaration of
@
namespace Ui {
class MainWindow;
}
@
and it shoudl be
@
Ui::MainWindowClass *ui;
@so in cpp something like:
@
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
...
@I hope that help somehow.
-
Thanks for all the advice guys, but i turned out to be none of the suggested ideas so I followed gramo's advice and made the appropriate changes.