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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:32:47+00:00 2026-05-25T11:32:47+00:00

I have two classes under QT, one to make a form, the other to

  • 0

I have two classes under QT, one to make a form, the other to send the collected data on the serial port. There is a button to submit and send the information on the serial port. The first class “myform” contains the file descriptor variable and the slot function for the submit button.

    class myform: public QWidget
    {
      Q_OBJECT
      private slots:
      void submitclicked(void);
    public:
        myform(QWidget *parent = 0);

        // some vars...  
        QPushButton *submit;
        int serialfd;
    };

The second class “serialcom” inherits the first class, since I want to implement the slot function in that “serialcom” class.

    class serialcom : public myform
    {
        Q_OBJECT
    public:
        int serialdev_init(void);
        serialcom(myform *parent=0);

    private:
        // some vars...
    };

The serialfd file descriptor is getting initialized in the constructor for serialcom through serialdev_init(). I have checked, it is initialized properly. The problem is that when the SLOT for submit button is called, serialfd has garbage value (I mean inside the submitclicked() slot ), not the initialized value.

Isn’t it supposed to preserve the value, or am I wrong to assume that ? I am pretty new to this QT or even C++ business, so please mind my stupidities if any…

Here is the main function…

    int main(int argc,char **argv)
    {
        QApplication app(argc,argv);

        myform *trial = new myform;

        serialcom *serial = new serialcom(trial);


        trial->show();

        return app.exec();
   }

Any other suggestions are also welcome.

  • 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-25T11:32:48+00:00Added an answer on May 25, 2026 at 11:32 am

    Derived class construction involves base class sub-object construction first followed by derived class sub-object. So, derived class object has two sub-objects.

     myform *trial = new myform;
    

    trail has a sub-objects of type QWidget, myform. Now this myform sub-object has it’s own member variable(s) serialfd which is uninitialized. Now, trial cannot access serialcom members because a derived class can access base class members but the otherwise is not true.

     serialcom *serial = new serialcom(trial);
    

    The same happens with this statement too except that serial has it’s own sub-objects QWidget, myform, serial.

    The serialfd file descriptor is getting initialized in the constructor for serialcom through serialdev_init().

    Now the two myform sub-objects has no relation. You are setting serialfd of this sub-object but seeing the serialfd of trail sub-object.

     trial->show();
    

    Hope you understood what you are doing wrong.

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

Sidebar

Related Questions

I have two classes, and want to include a static instance of one class
I have two classes that each need an instance of each other to function.
For example, I have a directory structure like this: my_stuff classes one two more
I have two same project in which I have two classes under same namespace
I have two classes that communicate with each other (processes in each class depend
for example, we have two classes for parsing the resumes, one to parse Excel
I have two classes with nested generics. Is there a way to get rid
I have two classes. One(Person) for getters and setters, and another(People) for compute the
I have two classes. One is a management class, which stores a bunch of
I have two classes that are almost identical, besides one method. The classes have

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.