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. Sharing 1 QSharedPointer across 2 classes?
Forum Updated to NodeBB v4.3 + New Features

Sharing 1 QSharedPointer across 2 classes?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 222 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.
  • C Offline
    C Offline
    Calicoder
    wrote on last edited by
    #1

    Good day, was wondering if this is possible as I can't seem to see it documented in the official docs. I have 2 classes AppWidgetA and AppWidgetB that I'd like to store the QSharedPointer<QString> newStrings in another class called AppWidget. Something like this might work:

    AppWidget.h

    class AppWidget : public QWidget
    {
    	private:
    		QSharedPointer<QString> newStrings;
    };
    

    AppWidgetA.cpp:

    void AppWidgetA::addStringA()
    {
    	newStrings->append("Test A");
    }
    

    AppWidgetB.cpp:

    void AppWidgetB::addStringB()
    {
    	newStrings->append("Test B");
    }
    

    Thanks for any help / tips.

    Christian EhrlicherC 1 Reply Last reply
    0
    • C Calicoder

      Good day, was wondering if this is possible as I can't seem to see it documented in the official docs. I have 2 classes AppWidgetA and AppWidgetB that I'd like to store the QSharedPointer<QString> newStrings in another class called AppWidget. Something like this might work:

      AppWidget.h

      class AppWidget : public QWidget
      {
      	private:
      		QSharedPointer<QString> newStrings;
      };
      

      AppWidgetA.cpp:

      void AppWidgetA::addStringA()
      {
      	newStrings->append("Test A");
      }
      

      AppWidgetB.cpp:

      void AppWidgetB::addStringB()
      {
      	newStrings->append("Test B");
      }
      

      Thanks for any help / tips.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      So what's the problem - a QSharedPointer is like any other pointer - you can pass it around and store it wherever you want.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      C 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        So what's the problem - a QSharedPointer is like any other pointer - you can pass it around and store it wherever you want.

        C Offline
        C Offline
        Calicoder
        wrote on last edited by
        #3

        @Christian-Ehrlicher Oh that's good to know thank you.

        1 Reply Last reply
        0
        • C Calicoder has marked this topic as solved on

        • Login

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