QT posix message queue



  • HI i'm new to QT.
    I have one application sending data packets to message queue. And my second application is QT. i have to receive that data from qt. How can i use posix message queue commands in qt??(like mq_receive). Please help.


  • Moderators

    @jish This is not related to Qt.
    You use message queues in your Qt app as in any other C/C++ app.
    Qt is a C++ framework, so you can use C APIs directly.
    So you simply do it like in your first app.



  • @jsulm so no need to use header files specific to qt? mqueue.h is not working with qt.


  • Moderators

    @jish Sorry, but how is it related to Qt? You need Qt header files if you use Qt. If I understood you correctly your second app uses Qt, so you need to include needed Qt header files - it doesn't matter whether this app uses message queues or not.


  • Moderators

    @jish "mqueue.h is not working with qt" - why? What happens? Qt is not a programming language...



  • @jsulm for using mq_send/mq_receive i need to add mqueue.h to my QT program. But it shows no such file or directory


  • Moderators

    @jish Can you show how you're doing this? Did you check that you have mqueue.h ?
    "But it shows no such file or directory" - who shows this? Is it an error during compiling? Is it shown in QtCreator?



  • @jsulm yes..it is an error during compilation in qtcreator


  • Moderators

    @jish Do you have this header file in your system?
    And can you show how you include it in your code?



  • @jsulm #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <Mqueue.h>
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    mqd_t mqid;
    mqid=mq_open("/hmi_chnl_ic",O_RDONLY);
    if(mqid==-1)
    {
    QDebug()<<"error opening message queue";
    }
    }
    this is the sample code..please forgive me if i'm asking anything stupid.And please do tell me where do ineed to add mqueue.h to get that in my program.


  • Moderators

    @jish said in QT posix message queue:

    #include <Mqueue.h>

    it must be

    #include <mqueue.h>
    

    You need to include it where you want to use it. Where it is depends on your design.



  • @jsulm mqueue.h is also not working..
    You need to include it where you want to use it??? i tried to include it with the headers in .pro file..but no use.


  • Moderators

    @jish "mqueue.h is also not working" - if you say something is not working you should always say what exactly is not working...
    I already asked you two times whether you have this header file in your system. Can you please answer this question?

    "You need to include it where you want to use it???" - before you asked "And please do tell me where do ineed to add mqueue.h to get that in my program". Maybe I misunderstood your question. You do not need to add this header file to your project. You just use it - system headers files are never added to the project directly.
    "i tried to include it with the headers in .pro file..but no use" - this is not needed! mqueue.h is usually already installed in your system (I guess you're using Linux?).
    This simple program should compile:

    #include "mqueue.h"
    
    int main(void)
    {
        return 0;
    }
    

    Does it compile if you do it like this:

    g++ -o test_mqueue test_mqueue.cpp
    

    ?



  • @jsulm no idont have this header file in my system.That is why i'm asking where do add this header.


  • Qt Champions 2016

    @jish
    Its a linux header. Not related to Qt at all. This is where it is on my system

    alt text


  • Moderators

    @jish Do you use a Linux distribution?
    If so then install needed package. On Ubuntu you need to install libc6-dev package.



  • @jsulm i'm using linux distribution.
    i am able to use mqueue.h in my linux program without any error. Only using with qt showed the error message.


  • Moderators

    @jish It would be helpful to know which one.
    What does

    find /usr -name mqueue.h
    

    output?



  • @jsulm said in QT posix message queue:

    find /usr -name mqueue.h

    output
    /usr/include/mqueue.h
    /usr/include/x86_64-linux-gnu/bits/mqueue.h
    /usr/include/linux/mqueue.h
    /usr/src/linux-headers-3.13.0-24-generic/include/config/posix/mqueue.h
    /usr/src/linux-headers-3.13.0-117/include/uapi/linux/mqueue.h
    /usr/src/linux-headers-3.13.0-117-generic/include/config/posix/mqueue.h
    /usr/src/linux-headers-3.13.0-24/include/uapi/linux/mqueue.h


  • Moderators

    @jish What is the error message after changing

    #include <Mqueue.h>
    

    to

    #include <mqueue.h>
    

    ?


  • Moderators

    @jish Can you upload your project to somewhere? I then can try to build it on my machine.



  • @jsulm same..no such file or directory.
    And i can't upload the the project since i'm working with a company.
    Can you please try open a message queue using mq_open in qt creator?


  • Moderators

    @jish This builds on my machine in QtCreator:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QDebug>
    
    #include <mqueue.h>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        mqd_t mqid;
        mqid=mq_open("/hmi_chnl_ic",O_RDONLY);
        if(mqid==-1)
        {
            qDebug()<<"error opening message queue";
        }
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    pro file:

    #-------------------------------------------------
    #
    # Project created by QtCreator 2017-05-19T09:26:01
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = test_mqueue
    TEMPLATE = app
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    LIBS += -lrt
    
    SOURCES += main.cpp\
            mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    
    

    You need to add -lrt to be able to link.



  • @jsulm omg that solved my issue. Thank you very much.
    one question where you saved mqueue.h in your system?


Log in to reply