QT Linking Issues
| Required Info | |
|---|---|
| Camera Model | SR300 |
| Operating System & Version | Windows 10 |
| SDK Version | 2.0 |
Hi, I have compiled the libraries from source in Windows 10 using VisualStudio. When I link the libraries in VisualStudio 2017, it works fine and runs the examples. However, I have created a simple qt project with an empty main function, where I'm only doing a "#include <librealsense2/rs.hpp>".
By doing that and hitting compile, I get many sintax errors from rs_frame.hpp, which don't really make any sense. I'm attaching my .pro file for reference.
Regards, Raphael.
Hello @cardosoraph, I think I already had this problem. You have to include librealsense headers before any other QT header. This should be because QT uses a custom syntax for the foreach and it cause some problems with the one used in rs_frame.hpp
Hi @callendorph and @Jiloc ,
Can you please check if changing the foreach(...) in rs_frame.hpp into: this->foreach(...) resolves the issue without reordering the include lines?
Unfortunately It doesn't, just to be clear, the line is this. Unfortunately also the void foreach(T action) const definition causes problems
Sounds strange as the functions is nested in the rs2 namespace, is the QT foreach a macro? (Sorry for the hassle, I don't have a QT project to test this with)
The simplest way to solve this is to rename foreach in rs_frame.hpp. There are only two places where you have to rename 'foreach' to something like 'foreachRS'
line 542
template
and line 484 frame first_or_default(rs2_stream s) const { frame result; foreachRS([&result, s](frame f){ if (!result && f.get_profile().stream_type() == s) ...
This will solve the Problem.
@zivsha yes it is a macro
I see. Makes sense that it is a macro, same issue as the infamous min/max of windows. We will consider changing the name of the function to avoid such issues in the future, thanks for the help guys!
@cardosoraph , I assume this will resolve your issue so I closed it. Please feel free to open a new issue if you need further assistance
I am working off master, and this is still an issue when trying to work with Qt5. Can we please keep this open until it is resolved by a PR -- or explicitly closed as a wontfix?
+1 for resolving by changing the name of foreach in rs_frame.hpp
(note: this is what we have done with our local builds)
If this is part of a public interface that people outside the librealsense library are using, maybe we can disable the macro only within the region where it is being applied to librealsense: https://stackoverflow.com/questions/1543736/how-do-i-temporarily-disable-a-macro-expansion-in-c-c
foreach name clash with qt MACRO still persists.
Renaming librealse-defined foreach to foreachRS in rs_frame.hpp solves the problem.