Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. overload a pure function in plugin interface is crashed.
Forum Updated to NodeBB v4.3 + New Features

overload a pure function in plugin interface is crashed.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 317 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QtTester
    wrote on last edited by
    #1

    hi guys.
    here is my interface for a qplugin:

    class base{
    public :
    virtual ~basse() = default;
    virtual int func(int ) = 0;
    };
    class drived:public base{
    public :
      int func(int ) override{
        return 0;
      };
    };
    

    Now a exe app uses QPluginLoader() to call this plugin is fine.
    Then we need to add a new func like this:

    class base{
    public :
    virtual ~basse() = default;
    virtual int func(int ) = 0;
    // OVERRIDE same pure function
    virtual int func(char,char ) = 0;
    };
    class drived:public base{
    public :
      int func(int ) override{
        return 0;
      };
      int func(char a,char b) override{
        return 0;
      };
    };
    

    BUT WITHOUT compile the exe , we run the exe then it crashed!!
    If change it to:

    class base{
    public :
    virtual ~basse() = default;
    virtual int func(int ) = 0;
    // just a new pure function
    virtual int func2(char,char ) = 0;
    };
    class drived:public base{
    public :
      int func(int ) override{
        return 0;
      };
      int func2(char a,char b) override{
        return 0;
      };
    };
    

    STILL NOT compile exe , calling is OK!!!
    SO, Why I define a overload pure function will lead to a crash?
    class drive wil hide base::func() and just map to one function?

    jsulmJ 1 Reply Last reply
    0
    • Q QtTester

      hi guys.
      here is my interface for a qplugin:

      class base{
      public :
      virtual ~basse() = default;
      virtual int func(int ) = 0;
      };
      class drived:public base{
      public :
        int func(int ) override{
          return 0;
        };
      };
      

      Now a exe app uses QPluginLoader() to call this plugin is fine.
      Then we need to add a new func like this:

      class base{
      public :
      virtual ~basse() = default;
      virtual int func(int ) = 0;
      // OVERRIDE same pure function
      virtual int func(char,char ) = 0;
      };
      class drived:public base{
      public :
        int func(int ) override{
          return 0;
        };
        int func(char a,char b) override{
          return 0;
        };
      };
      

      BUT WITHOUT compile the exe , we run the exe then it crashed!!
      If change it to:

      class base{
      public :
      virtual ~basse() = default;
      virtual int func(int ) = 0;
      // just a new pure function
      virtual int func2(char,char ) = 0;
      };
      class drived:public base{
      public :
        int func(int ) override{
          return 0;
        };
        int func2(char a,char b) override{
          return 0;
        };
      };
      

      STILL NOT compile exe , calling is OK!!!
      SO, Why I define a overload pure function will lead to a crash?
      class drive wil hide base::func() and just map to one function?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @QtTester said in overload a pure function in plugin interface is crashed.:

      // OVERRIDE same pure function
      virtual int func(char,char ) = 0;

      This is NOT overriding, but overloading! You just added a new pure virtual method.

      "STILL NOT compile exe , calling is OK!!!" - I don't get it. If you can't compile you also cannot run it. Can you please explain better?
      And if you get compiler errors: why don't you post those?!

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      1
      • jsulmJ jsulm

        @QtTester said in overload a pure function in plugin interface is crashed.:

        // OVERRIDE same pure function
        virtual int func(char,char ) = 0;

        This is NOT overriding, but overloading! You just added a new pure virtual method.

        "STILL NOT compile exe , calling is OK!!!" - I don't get it. If you can't compile you also cannot run it. Can you please explain better?
        And if you get compiler errors: why don't you post those?!

        Q Offline
        Q Offline
        QtTester
        wrote on last edited by QtTester
        #3

        @jsulm
        Sorry, pls let me explain more.

        1. overload is right. i was wrong.
        2. the plugin project generates a DLL file.
          in another exe project, it just use qpluginloader() to load the dll, so if we don't comile exe project, just double click the exe to run, it can still load the dll file,right?
          generally speaking, if we just add pure virtual function to the tail of the class, the calling won't be crash, because the virtual function table order is not changed for the uncompiled caller(exe). Unless we change the order,like this:
        class base{
        public :
        virtual ~basse() = default;
        // insert an interface before old one, uncompiled caller will be crash
        virtual int func(char,char ) = 0;
        virtual int func(int ) = 0;
        
        };
        
        1. exe call the func() like this pseudo code:
        base *obj = drived();
        obj->func(2);
        

        when overload a new func(char,char), it crash, but if we rename to func2(char,char),it runs fine.
        So i doubt the same name 'func' did something I don't know.

        jsulmJ 1 Reply Last reply
        0
        • Q QtTester

          @jsulm
          Sorry, pls let me explain more.

          1. overload is right. i was wrong.
          2. the plugin project generates a DLL file.
            in another exe project, it just use qpluginloader() to load the dll, so if we don't comile exe project, just double click the exe to run, it can still load the dll file,right?
            generally speaking, if we just add pure virtual function to the tail of the class, the calling won't be crash, because the virtual function table order is not changed for the uncompiled caller(exe). Unless we change the order,like this:
          class base{
          public :
          virtual ~basse() = default;
          // insert an interface before old one, uncompiled caller will be crash
          virtual int func(char,char ) = 0;
          virtual int func(int ) = 0;
          
          };
          
          1. exe call the func() like this pseudo code:
          base *obj = drived();
          obj->func(2);
          

          when overload a new func(char,char), it crash, but if we rename to func2(char,char),it runs fine.
          So i doubt the same name 'func' did something I don't know.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @QtTester I'm still not sure I understand: do you mean you change base class without rebuilding the derived one?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved