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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:09:41+00:00 2026-05-16T11:09:41+00:00

Environment: Linux C++ / Qt 4x I do not understand why the following downcast

  • 0

Environment: Linux C++ / Qt 4x

I do not understand why the following downcast returns NULL? I pasted base and derived class below.

Thanks in advance for any tips or suggestions.

-Ed

void MainWindow::onRtledaEventHandler(fes::EventArgs eventArgs)
{
   // This cast returns a NULL ?
   fes::AtsCommandEventArgs* atsCommandEventArgs = dynamic_cast<fes::AtsCommandEventArgs*>(&eventArgs);
}


/// The base class for containing event arguments sent to clients using boost::signals2
class EventArgs
{
public:

   EventArgs() {}
   EventArgs(RtledaEventType eventType) :
         m_eventType(eventType) {}
   EventArgs(const EventArgs& eventArgs) :
         m_eventType(eventArgs.m_eventType) {}
   virtual ~EventArgs() {}

   /// The type of event this is
   RtledaEventType eventType() const { return m_eventType; }

protected:
   RtledaEventType m_eventType;
};

// Derived class I am trying to upcast to
class AtsCommandEventArgs : public EventArgs
{
public:
   /// \param [in] lraddsPacketError LRADDS oacket error structure
   /// \sa fes::StructPacketStats_t packetStats
   AtsCommandEventArgs(fes::AtsCommand atsCommand, std::string messageBuffer, std::string details) :
         EventArgs(RtledaEventTypeAtsCommand),
         m_atsCommand(atsCommand),
         m_messageBuffer(messageBuffer),
         m_details(details) {}

   AtsCommandEventArgs(const AtsCommandEventArgs& AtsCommandEventArgs) :
         EventArgs(AtsCommandEventArgs),
         m_atsCommand(AtsCommandEventArgs.m_atsCommand),
         m_messageBuffer(AtsCommandEventArgs.m_messageBuffer),
         m_details(AtsCommandEventArgs.m_details) {}

   AtsCommandEventArgs() {}
   ~AtsCommandEventArgs() {}

   fes::AtsCommand atsCommand() const { return m_atsCommand; }
   std::string messageBuffer() const { return m_messageBuffer; }
   std::string details() const { return m_details; }

private:
   fes::AtsCommand m_atsCommand;
   std::string m_messageBuffer;
   std::string m_details;
};

Thanks in advance for any tips or suggestions,

-Ed

  • 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-05-16T11:09:41+00:00Added an answer on May 16, 2026 at 11:09 am

    You are passing a fes::EventArgs object by-value, which means it is a fes::EventArgs object. If you want to preserve the original type of polymorphic objects, pass a pointer or (better) a reference to them:

    void MainWindow::onRtledaEventHandler(fes::EventArgs& eventArgs) {
       fes::AtsCommandEventArgs& atsCommandEventArgs = dynamic_cast< fes::AtsCommandEventArgs&>(eventArgs);
    }
    

    Note that dynamic_cast throws std::bad_cast in case of failure if applied to references.

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

Sidebar

Related Questions

My environment: Rails 3.2.x with RVM, Passenger, Apache on Linux (Ubuntu), I am not
Following is my environment: Linux, Ubuntu C++/gdb Eclipse I am implementing a TCP socket
In an embedded linux environment (customized 2.4.25 on PowerPC) I get the following kernel
Thanks for your time and sorry for this long message! My work environment Linux
How would you approach benchmarking the following XSL:T process. Testing environment: a Linux server
I'm working on a web site under a Linux environment (Debian). I'm not an
I just finished up a class in C/C++ in a Linux environment and when
I am quite new to the embedded linux programming and did not really understand
Using Linux environment with java,I'm having the config file which should be configured before
In Linux environment, I want to create a file and write text into it:

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.