Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenNI callback gets deregistered when Qt GUI is initiated #1028

Closed
indianajohn opened this issue Dec 3, 2014 · 5 comments
Closed

OpenNI callback gets deregistered when Qt GUI is initiated #1028

indianajohn opened this issue Dec 3, 2014 · 5 comments
Assignees

Comments

@indianajohn
Copy link

Hi,

I have tested this issue on PCL 1.7.2 and also the most recent Github release on Ubuntu 14.04 (PCL 1.7.2 from the package system and also custom compiled). I tried linking against both VTK 5.x, 6.x, and the latest Gthub version, as well as Qt 4.x and 5.x. I have also tested this on PCL 1.7.2 on Windows.

Whenever A Qt GUI is started, all cloud callbacks seem to become deregistered. This problem can be reproduced by starting from visualizer:

https://github.com/PointCloudLibrary/pcl/tree/master/doc/tutorials/content/sources/qt_visualizer

adding a callback function to main.h, starting it, sleeping for a bit, and starting the GUI:

#include "pclviewer.h"
#include <QApplication>
#include <QMainWindow>
#include <pcl/io/openni_grabber.h>

int g_nCallbackCount;

void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZA>::ConstPtr &cloud)
{
std::cout << "Hello from the callback" << g_nCallbackCount << std::endl;
g_nCallbackCount++;
}

int main (int argc, char *argv[])
{
// Register callback
pcl::Grabber* interface = new pcl::OpenNIGrabber();
g_nCallbackCount = 0;
boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
boost::bind (&cloud_cb_);
interface->registerCallback (f);
interface->start ();

// Wait a bit
sleep(5);

// Start the GUI
QApplication a (argc, argv);
PCLViewer w;
w.show ();
interface->stop ();
delete interface;
return a.exec ();
}

The program starts, calls the callback for 5 seconds, and then the callback dies as the GUI comes up.

I suspect this has to do with namespace collision between boost::signals2 and Qt signals.
http://www.boost.org/doc/libs/1_55_0/doc/html/signals/s04.html

I would appreciate any help with this as I am trying to make a Qt GUI for a program that accesses a Xtion sensor and it's impossible with this bug present.

Thank you.

Best Regards,
John

@67shafar
Copy link

67shafar commented Sep 3, 2015

Hello,

I know this is late but I had the exact same problem just now. Your intuition was correct.
You can fix this by adding:
ADD_DEFINITIONS(-DQT_NO_KEYWORDS)

to your CMakelists.txt file. You will also want to make sure it comes before ${QT_DEFINITIONS} if that exists in your CMakelists.txt file.

In my case I have this:
ADD_DEFINITIONS (-DQT_NO_KEYWORDS ${QT_DEFINITIONS})

Just make sure that when u need signals or slots you use the type Q_SLOTS or Q_SIGNALS.

@indianajohn
Copy link
Author

Thanks for the solution.. it actually helps my current work. I'll leave this open for the time being because this is a pretty baffling pitfall and maybe this flag should be added such that it automatically makes its way into programs linked against PCL.

@taketwo
Copy link
Member

taketwo commented Oct 23, 2015

I think we should convert to use Q_SLOTS and Q_SIGNALS instead of keywords everywhere in PCL to avoid possible conflicts. For example, this has been done in WebKit.

@taketwo taketwo self-assigned this Oct 23, 2015
taketwo added a commit to taketwo/pcl that referenced this issue Jun 24, 2017
This is to avoid compile errors when including 3rd party headers. In
particular, boost signals library is known to cause problems, see PointCloudLibrary#1028.
taketwo added a commit to taketwo/pcl that referenced this issue Jun 24, 2017
This is to avoid compile or runtime problems when including 3rd party
headers. In particular, boost signals library is known to cause
problems, see PointCloudLibrary#1028.
@taketwo
Copy link
Member

taketwo commented Jun 24, 2017

I could not reproduce this issue with latest PCL, Qt5, and OpenNI2 grabber. Callback continues to fire after the GUI shows up. Nevertheless, I've submitted a patch converting to Q_* since it is generally a good idea not to use these keywords.

@SergioRAgostinho
Copy link
Member

Should be closed with #1898. Please reopen if necessary.

UnaNancyOwen pushed a commit to UnaNancyOwen/pcl that referenced this issue Nov 24, 2017
This is to avoid compile or runtime problems when including 3rd party
headers. In particular, boost signals library is known to cause
problems, see PointCloudLibrary#1028.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants