Problem 'undeclared identifier'
-
wrote on 15 May 2012, 03:44 last edited by
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 identifierHowever I already place this identifier on the mainwindow.h, public section.
Please help and sorry for my English.thank you
:) -
"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.
-
wrote on 17 May 2012, 01:05 last edited by
Thank you, I will try to translate your suggestion in code. It hard for me but i will try....thank again friend..
-
wrote on 17 May 2012, 05:54 last edited by
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
-
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.
-
wrote on 22 May 2012, 03:18 last edited by
Thank again Mr. sierdzio.. I will try. It is very nice help from you.*
1/6