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. Problem 'undeclared identifier'
Forum Updated to NodeBB v4.3 + New Features

Problem 'undeclared identifier'

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 18.3k 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.
  • R Offline
    R Offline
    romeo.rbw
    wrote on last edited by
    #1

    Hi Qt-ers,
    I would like to ask for help.
    I have a Main Window and there are a Widget for displaying a camera frame capture and a button in that Main Window.
    When a button was clicked there is a new form (2nd form)displayed. In the 2nd form there is a widget too, that I hope can display the same frame capture from camera. The problem is, the Widget in Main Window was succedded in displaying the frame. But the second is not. I use mOrigImage as the name of my data matrix of image capture (because I used openCV, cv::Mat type). Is it possible that one identifier used by two windows?
    There is an error message:
    formdisplay.cpp:13: error: C2065: 'mOrigImage' : undeclared identifier

    However I already place this identifier on the mainwindow.h, public section.
    Please help and sorry for my English.

    thank you
    :)

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      "public" means "publicly accessible". It does not mean that the same identifier can be used everywhere. If you wan to access this variable from your other widget without changing much, you have to:

      • make sure mainwindow is visible from 2nd widget
      • access the variable in this manner: mainwindow.mOrigImage

      But, to say the least, this is NOT what I would recommend. Much better solution would be to:

      In mainwindow - declare mOrigImage as private pointer

      When you construct the 2nd widget - pass the pointer to that widget (for example in a new constructor, or a separate method)

      Use them both independently

      ... or something. There are many possibilities and I don't know your use case exactly.

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        romeo.rbw
        wrote on last edited by
        #3

        Thank you, I will try to translate your suggestion in code. It hard for me but i will try....thank again friend..

        1 Reply Last reply
        0
        • R Offline
          R Offline
          romeo.rbw
          wrote on last edited by
          #4

          Hai... I try to get the reference of private pointer like your suggestion. Is that you mean:
          private:
          ......*mOrigImage; ??

          but I do not have a class name in the ".....", Could you help me how to code this. Thank you in advance

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            I would suggest grabbing a C++ book or online tutorial.

            Here's what it might look like:
            @
            // Main window header:
            class MyMainWindow : public QMainWindow
            {
            /* allthe rest of the code */
            public slots:
            void on_button_clicked(); // This is the slot handling your button click.

            private:
            cv::Mat *myOrigImage;
            SecondWidget *secondWidget;
            }

            // Main window source (just the relevant part):
            void MyMainWindow::on_button_clicked() {
            if (!secondWidget) {
            secondWidget = new SecondWidget(this, mOrigImage);
            }

            secondWidget->show();
            

            }
            @

            You have not specified, what kind of widget that "second widget" is. I will assume a QDialog. If it is different, the implementation may differ.
            @
            // Header:
            class SecondWidget : public QDialog
            {
            public:
            SecondWidget(QWidget *parent, cv::Mat *image);

            private:
            cv::Mat *mOrigImage;
            }

            // Source:
            SecondWidget::SecondWidget(QWidget *parent, cv::Mat *image) : QDialog(parent), mOrigImage(image)
            {
            }
            @

            It's just a quick sketch, I'm not saying it will work 100% ;) Also, remember to properly delete the mOrig object when it is no longer needed.

            (Z(:^

            1 Reply Last reply
            0
            • R Offline
              R Offline
              romeo.rbw
              wrote on last edited by
              #6

              Thank again Mr. sierdzio.. I will try. It is very nice help from you.*

              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