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. How to access QStringList present in 1 class in all other the remaning classes?

How to access QStringList present in 1 class in all other the remaning classes?

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++qt 5.4oopclasses
6 Posts 3 Posters 665 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.
  • L Offline
    L Offline
    learnist
    wrote on 13 Aug 2020, 06:32 last edited by
    #1

    i have a QStringList in 1 class

    completer.cpp

    #include "completer.h"
    
    Completer::Completer(QObject *parent)
        : QObject(parent)
    {
    }
    Completer::~Completer()
    {
    }
    

    completer.h

    #pragma once
    #include <QObject>
    
    class Completer : public QObject
    {
        Q_OBJECT
    public:
        Completer(QObject *parent);
        ~Completer();
        QStringList global_completer_list;
    };
    

    i also have 3 other Dialog classes, all of the dialogs contain QLineedits , one of the class is named as car.h and car.cpp, so , my question is how do i create an object of completer class and access the QStringlist of completer class in all another classes, i am having syntax problems.

    J J 2 Replies Last reply 13 Aug 2020, 06:39
    0
    • L learnist
      13 Aug 2020, 06:32

      i have a QStringList in 1 class

      completer.cpp

      #include "completer.h"
      
      Completer::Completer(QObject *parent)
          : QObject(parent)
      {
      }
      Completer::~Completer()
      {
      }
      

      completer.h

      #pragma once
      #include <QObject>
      
      class Completer : public QObject
      {
          Q_OBJECT
      public:
          Completer(QObject *parent);
          ~Completer();
          QStringList global_completer_list;
      };
      

      i also have 3 other Dialog classes, all of the dialogs contain QLineedits , one of the class is named as car.h and car.cpp, so , my question is how do i create an object of completer class and access the QStringlist of completer class in all another classes, i am having syntax problems.

      J Offline
      J Offline
      JonB
      wrote on 13 Aug 2020, 06:39 last edited by JonB
      #2

      @learnist
      Not sure what your problem is, as this is just C++, and has nothing to do with QStringList, or even Qt:

      #include "completer.h"
      ...
      Completer *completer = new Completer;
      ...
      qDebug() << completer->global_completer_list;
      
      L 2 Replies Last reply 13 Aug 2020, 06:49
      1
      • J JonB
        13 Aug 2020, 06:39

        @learnist
        Not sure what your problem is, as this is just C++, and has nothing to do with QStringList, or even Qt:

        #include "completer.h"
        ...
        Completer *completer = new Completer;
        ...
        qDebug() << completer->global_completer_list;
        
        L Offline
        L Offline
        learnist
        wrote on 13 Aug 2020, 06:49 last edited by
        #3

        @JonB Agreed , not Qt , but more of OOPS concepts problem, i want to know how can i access the QStringList in my new class (a.cpp and a.h), where do i place your code, in my .h or .cpp ?

        1 Reply Last reply
        0
        • L learnist
          13 Aug 2020, 06:32

          i have a QStringList in 1 class

          completer.cpp

          #include "completer.h"
          
          Completer::Completer(QObject *parent)
              : QObject(parent)
          {
          }
          Completer::~Completer()
          {
          }
          

          completer.h

          #pragma once
          #include <QObject>
          
          class Completer : public QObject
          {
              Q_OBJECT
          public:
              Completer(QObject *parent);
              ~Completer();
              QStringList global_completer_list;
          };
          

          i also have 3 other Dialog classes, all of the dialogs contain QLineedits , one of the class is named as car.h and car.cpp, so , my question is how do i create an object of completer class and access the QStringlist of completer class in all another classes, i am having syntax problems.

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 13 Aug 2020, 06:49 last edited by
          #4

          @learnist the fact that you have a public member variable named global_completer_list screams spaghetti code with global variables to me!

          You should probably rethink and redesign your application concept!


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1
          • J JonB
            13 Aug 2020, 06:39

            @learnist
            Not sure what your problem is, as this is just C++, and has nothing to do with QStringList, or even Qt:

            #include "completer.h"
            ...
            Completer *completer = new Completer;
            ...
            qDebug() << completer->global_completer_list;
            
            L Offline
            L Offline
            learnist
            wrote on 13 Aug 2020, 07:00 last edited by
            #5

            @JonB i get the error no default constructor exists for class "Completer" in

            Completer *completer = new Completer;
            
            J 1 Reply Last reply 13 Aug 2020, 07:04
            0
            • L learnist
              13 Aug 2020, 07:00

              @JonB i get the error no default constructor exists for class "Completer" in

              Completer *completer = new Completer;
              
              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 13 Aug 2020, 07:04 last edited by
              #6

              @learnist
              either

              Completer(QObject *parent = nullptr);
              

              or

              Completer *completer = new Completer(nullptr);
              

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              2

              1/6

              13 Aug 2020, 06:32

              • Login

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