实施 QRCodeReader (ZXing) 的问题
因此,我按照此处提到的步骤操作: http://zxing.googlecode.com/svn /trunk/iphone/README
我确保一切正常,但我的 QRCodeReader 在 myVC.mm 文件中未被识别。
这是什么情况: 该项目已放入我自己的项目中,如链接中所述。 我已在头文件中导入了 #import "ZXingWidgetController.h"
并且它正在被识别。 我已在实现文件 (.mm) 中导入了 #import "QRCodeReader.h"
然后我将它们都分配在某个按钮的目标方法中,如下所示:
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];
现在它告诉我这就是问题所在:
QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
[qrcodeReader release];
它说:使用未声明的标识符'QRCodeReader'
- 为什么它看不到我导入的QRCodeReader 中的似乎 .mm 文件?
- 我忘记了哪些不在我使用的描述中的内容?
- 最重要的是,如何修复此问题以识别 QRCodeReader?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
直接的 C++ 代码(不是 Objective C++)使用 C++ 命名空间。
您需要说
zxing::qrcode::QRCodeReader
或使用using
语句,例如Update:
上面的代码确实引入了 C++ 类,但是实际上有一个同名的小部件类,我忘记了。它是一个 Objective C 类,它包装了 C++ 类,并且正是您想要的。而不是上面的代码,只需
#import "QRCodeReader.h"
...您说的那样。我预计两个同名文件会发生冲突。包含 cpp 文件时是否设置了“递归”选项?自述文件说“不需要”,但可能应该说“不能”。这可能会导致包含 cpp 文件而不是小部件版本。The straight C++ code (not Objective C++) uses C++ namespaces.
You need to either say
zxing::qrcode::QRCodeReader
or useusing
statements likeUpdate:
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.我最后遇到了同样的问题,解决方案很简单。
我将 .mm 文件与“位置”放在一起 -> “相对于项目”。
希望这有帮助
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