Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Am i being stupid here?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Am i being stupid here?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Suths
    wrote on last edited by
    #1

    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;

    };
    @

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      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"

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Suths
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          Does your OpenShots class have a ";" at the end of the class definition?

          @
          class OpenShots ... {
          ...
          }; <-- here
          @

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Suths
            wrote on last edited by
            #5

            };

            #endif // OPENSHOTS_H

            yep sure did and the constructor for that class is OpenShots(QWidget *parent = 0);

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gmaro
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Suths
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved