Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8689193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:34:52+00:00 2026-06-12T23:34:52+00:00

I’d like to send a custom c++ class through the Qt DBUS API. I’ve

  • 0

I’d like to send a custom c++ class through the Qt DBUS API. I’ve created the class from the .proto file using the protoc compiler and added them to my project in QtCreator. Now I want to verify that I can send the custom class as a QVariant through the dbus API. I have a receiver and sender program and can send a simple test string so Dbus works. I am having trouble sending the protocol buffer class after adding it as a metatypes.

My test .proto file contains only ints:

message MyData {
  required int32 name = 1;
  required int32 id = 2;
  optional int32 email = 3;
}

To the protocol buffer class header file I added:

#include <QMetaType>
#include <QDBusMetaType>
...
friend QDBusArgument &operator<<(QDBusArgument &argument, const MyData &dataToWrite);
friend const QDBusArgument &operator>>(const QDBusArgument &argument, MyData &dataToWrite);
...
Q_DECLARE_METATYPE(MyData )

And to the protocol buffer class implementation file I added:

#include <QDebug>
...
#include <QMetaType>
#include <QDBusMetaType>

// Marshall the MyData data into a D-Bus argument
QDBusArgument &operator<<(QDBusArgument &argument, const MyData &dataToWrite)
{

    qDebug() << "OPERATOR<<";

    argument.beginStructure();

    // Break out the various properties of dataToWrite protocol buffer
    int name = dataToWrite.name();
    int id = dataToWrite.id();
    int email = dataToWrite.email();
    qDebug() << name;
    qDebug() << id;
    qDebug() << email;

    argument << name;
    argument << id;
    argument << email;
    argument.endStructure();
    return argument;

}

// Retrieve the MyData data from the D-Bus argument
const QDBusArgument &operator>>(const QDBusArgument &argument, MyData &dataToWrite)
{

    qDebug() << "OPERATOR>>";

    argument.beginStructure();

    // Break out the various properties of dataToWrite protocol buffer
    int name = dataToWrite.name();
    int id = dataToWrite.id();
    int email = dataToWrite.email();
    qDebug() << name;
    qDebug() << id;
    qDebug() << email;

    argument >> name;
    argument >> id;
    argument >> email;
    argument.endStructure();
    return argument;

}

Main simply looks like this:

QCoreApplication a(argc, argv);

    dbussender* client = new dbussender("com.one.two.three.nvram", "/dbusReadWriteNvRam", QDBusConnection::sessionBus(), 0);

    // Create a protocol buffer class and provide its properties with values
    MyData dataToWrite;
    dataToWrite.set_name(2);
    dataToWrite.set_id(3);
    dataToWrite.set_email(4);

    QString command3 = "Contacting Protobuf Receiver and calling WRITENVRAM...";
    QString response3 = client->writeNVRam(dataToWrite);

    std::cout << "Command:   " << command3.toStdString() << std::endl;
    std::cout << "Response:   " << response3.toStdString() << std::endl;

My dbussender class calls the remote function like this:

inline QDBusPendingReply<QString> writeNVRam(MyData dataToWrite)
    {

        qDebug() << "Sending " << dataToWrite.name();
        qDebug() << "Sending " << dataToWrite.id();
        qDebug() << "Sending " << dataToWrite.email();

        QList<QVariant> argumentList;
        argumentList << QVariant::fromValue<MyData>(dataToWrite);
        return asyncCallWithArgumentList(QLatin1String("writeNVRam"), argumentList);
    }

Ultimately in my receiver program, this function is called but always returns 0:

// Write NVRAM
QString dbusReadWriteNvRam::writeNVRam(MyData dataToWrite) {

    qDebug() << "WRITE NVRAM COMMAND CALLED";

    qDebug() << "Unpacking: " << dataToWrite.name();
    qDebug() << "Unpacking: " << dataToWrite.id();
    qDebug() << "Unpacking: " << dataToWrite.email();

    return "HELLO CLASS";

}

Here is the output of the Sender program:

Sending  2 
Sending  3 
Sending  4 
OPERATOR<< 
0 
0 
0 
OPERATOR<< 
2 
3 
4 
Command:   Contacting Protobuf Receiver and calling WRITENVRAM...
Response:   HELLO CLASS

And here is the output of the Receiver program:

OPERATOR<< 
0 
0 
0 
OPERATOR>> 
0 
0 
0 
WRITE NVRAM COMMAND CALLED 
Unpacking:  0 
Unpacking:  0 
Unpacking:  0

Why does it seem that the marshalling functions are being called twice? And howcome the second call seems to include the valid values of 2,3,4 for the 3 properties of my protocol buffer but the first call is all 0’s? The Receiver only seems to see the All 0’s and never receives a protocol buffer object with valid values.

Is there something wrong with my marshalling code? What else could be going on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:34:55+00:00Added an answer on June 12, 2026 at 11:34 pm

    To make this work, implement the operators like so:

    // PROTOBUF-MODIFICATION-DBUS
    // Marshall the companyData data into a D-Bus argument
    QDBusArgument &operator<<(QDBusArgument &argument, const companyData &dataToWrite)
    {
    
        argument.beginStructure();
    
        // Break out the various properties of dataToWrite protocol buffer
        int name = dataToWrite.name();
        int id = dataToWrite.id();
        int email = dataToWrite.email();
        argument << name;
        argument << id;
        argument << email;
        argument.endStructure();
        return argument;
    
    }
    
    // PROTOBUF-MODIFICATION-DBUS
    // Retrieve the companyData data from the D-Bus argument
    const QDBusArgument &operator>>(const QDBusArgument &argument, companyData &dataToWrite)
    {
    
        int name, id, email;
    
        argument.beginStructure();
        argument >> name;
        argument >> id;
        argument >> email;
        argument.endStructure();
        dataToWrite.set_name(name);
        dataToWrite.set_id(id);
        dataToWrite.set_email(email);
        return argument;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.