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 8861979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:37:02+00:00 2026-06-14T15:37:02+00:00

I have a problem with returning a const char* from two functions from a

  • 0

I have a problem with returning a const char* from two functions from a class, by some reason the first value is a replica of the second value or some values is wrong, but both values returned are from different pointers, in this case two QMap, the following is the code of the two functions:

const char* SomeClass::getSignal(QString signalName)
{
    QString signalsignature = this->signals.value(signalName);
    signalsignature.prepend(QString::number(QSIGNAL_CODE));
    QByteArray ba = signalsignature.toLatin1(); // i try toUTF8 and to Local8Bit
    const char* signalformated = ba.constData();
    return signalformated;
}

const char* SomeClass::getSlot(QString slotName)
{
    QString slotsignature = this->slots.value(slotName);
    slotsignature.prepend(QString::number(QSLOT_CODE));
    QByteArray ba = slotsignature.toLatin1();
    const char* slotformated = ba.constData();
    return slotformated;
}

The this->slot and the this->signals are QMap<QString, QString> that save slots and signals signatures ( somesignal(int) or someslot(bool) with keys somesignal, someslot respectively).

The class that i use is loaded from a DLL by QLibrary using an interface, all works fine using other functions from it, but using these functions like this:

const char* signal = someclassinstance->getSignal(tr("clicked"));
const char* slot = someclassinstance->getSlot(tr("onclicked"));

cout << "connecting signal " << signal << " to slot " << slot << endl;

this show me:

connecting signal clicked to slot rc

and the error when i use QObject::connect

Object::connect: Use the SLOT or SIGNAL macro to connect NovaRadioButton:: rc

I fill the QMaps is some function with:

signals.insert(methodname,QString(metamethod.signature()));

I don’t know what i am doing wrong or if maybe is a bug in Qt functions from QString, thanks for your help.

  • 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-14T15:37:03+00:00Added an answer on June 14, 2026 at 3:37 pm

    When your functions exit, the ba objects are destroyed. The pointers you return point inside memory locations of no longer existing objects. This is the basic (and well known) error of returning pointers to locals:

    char* foo()
    {
        char c = 'a';
        return &c;
    }
    

    The fact that you’re dealing with a QByteArray doesn’t matter; it’s still an automatic, local variable and thus gets destroyed on function exit.

    You should instead return a QByteArray directly, not a char*. This is still efficient, since QByteArray uses implicit sharing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is this, I have a base class from which classes are derived.
In several places I have to retrieve some value from a dict, but need
I have problem with returning a partial view from a controller with different model
I have a problem returning data back to the function I want it returned
I have problem with UIWebView delay when the load image from url. In my
I've just completed my second OOP class, and both my first and second classes
Hi everyone I'm having a problem. I have two SQL queries that are both
I have a problem that when I use something like this: const MyList& my_list
I have a problem with whether making class members constant or not. Let me
I have a problem returning an object that was created in other thread. 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.