[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"
-
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.