Ubuntu: How to use notify-send with C++?


I'm a C++ beginner coder. I'm trying to understand how to send notifications using libnotify-bin library. I've read some guys saying don't to use system calls. Any clue?


Okay so this is how I did it. First install libnotify-dev:

sudo apt-get install libnotify-dev  

this will install the lib on your system and put the headers of the lib to /usr/include/libnotify/

You can take a look at the header files to find out how to use the lib. I did the following:

#include <libnotify/notify.h>  #include <iostream>    int main(int argc, char * argv[] )   {      notify_init("Sample");      NotifyNotification* n = notify_notification_new ("Hello world",                                    "some message text... bla bla",                                    0);      notify_notification_set_timeout(n, 10000); // 10 seconds        if (!notify_notification_show(n, 0))       {          std::cerr << "show has failed" << std::endl;          return -1;      }      return 0;  }  

In order to build this type:

g++ hello_world.cc -o hello_world `pkg-config --cflags --libs libnotify`  

And here is the result:


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »