Question

So I've followed the steps mentioned here: http://zxing.googlecode.com/svn/trunk/iphone/README

And I made sure everything is alright but yet my QRCodeReader isn't being recognized in myVC.mm file.

This is what's the situation: The project is put into my own project as described in the link. I've imported the #import "ZXingWidgetController.h" in the header file and it is being recognized. I've imported the #import "QRCodeReader.h" in the implementation file (.mm) Then I alloced them both in a targetmethod of some button like this:

    ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
    widController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"qr_code_initialising_bg.png"]];
    QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
    NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
    [qrcodeReader release];
    widController.readers = readers;
    [readers release];
    [self presentModalViewController:widController animated:YES];

Now it tells me that this is the problem:

        QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
    NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
    [qrcodeReader release];

It says: Use of undeclared identifier 'QRCodeReader'

  • Why does it not see my import of the QRCodeReader in the seem .mm file?
  • What did I forget that is not in the description that I used?
  • And most important, how do I fix this to recognize the QRCodeReader?
Was it helpful?

Solution

The straight C++ code (not Objective C++) uses C++ namespaces.

You need to either say zxing::qrcode::QRCodeReader or use using statements like

  using namespace zxing;
  using namespace zxing::qrcode;

Update:

The code above does bring in the C++ class but there's actually a widget class of the same name which I forgot about. It is an Objective C class that wraps the C++ class and is what you want. Instead of the code above, just #import "QRCodeReader.h" ... which you said you did. I expect the two files of the same name are colliding. Did you set the "recursive" option when including the cpp files? The README says "don't need to" but should probably say "must not". That could cause the cpp file to be included and not the widget version.

OTHER TIPS

I had this exact same problem at the end the solution was kind of easy.

I put the .mm file with "Location" -> "Relative to Project".

Hope this help

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top