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. QList with custom class - accessing elements' methods
QtWS25 Last Chance

QList with custom class - accessing elements' methods

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 2.7k 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.
  • K Offline
    K Offline
    krisjobs
    wrote on last edited by
    #1

    Greetings,

    It maybe that I just can't formulate the right question to google it, but I've tried several times, could't find my exact problem though. So I thought, maybe you guys could help me out:

    The question is very simple:

    I have a custom class MyClass, I make a *QList<MyClass *> objList, I create a new instance of my class *MyClass obj, then I put it in the list: objList->append(obj).

    But when I try to call a member function of an element of the list
    objList->at(0)->...,
    AutoComplete shows nothing (no members of the object), as if it doesn't recognize that an object of MyClass is returned.
    When I manually type it: objList->at(0)->someFunction() it is working without a problem.

    So what troubles me is that QtCreator doesn't recognize the object returned from at(...) function, so that I can further call member functions. I am pretty sure I have misunderstood something along the way, so it would be kind if you would help me to clear this up.

    Thanks in advance, Kris.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Soraltan
      wrote on last edited by
      #2

      Hello,

      I tested what you described in my QtCreator and it works for me. Meaning I get all methods of the MyClass as suggestions from the Autocompletion.

      Could you provide more details, i.e. Qt Version, Creator Version and the actual code (in increasing importance ;-)).

      Thanks

      Soraltan

      1 Reply Last reply
      0
      • K Offline
        K Offline
        krisjobs
        wrote on last edited by
        #3

        Oh sorry, I totally forgot how important is that

        Qt Creator 2.7.2,
        Qt 5.1.0 (32 bit),

        @//in header
        QList<Waypoint *> *Waypoints;

        //in constructor
        Waypoints = new QList<Waypoint *>();

        //in a function
        {
        ...
        Waypoint *newWaypoint = new Waypoint();
        newWaypoint->sequenceId = 1;
        Waypoints->append(newWaypoint);
        ...
        qDebug() << Waypoints->at(0)
        // then when I press "." nothing happens,
        //and I must manually add "->sequenceId";
        }@

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Soraltan
          wrote on last edited by
          #4

          At first glance nothing strikes me as really odd. Let's clear some things I'm not 100% sure about:

          'In header' means that the Waypoints list is a class variable of a class A.

          In the corresponding cpp file you initialise that pointer with a new QList-object within class A's constructor.

          Within a method of class A then occurs the last piece of code.

          Are those assumptions correct?

          Then I have two additional questions:

          When you press '.' and QtCreator recognises its a pointer it is usually translated to '->'. Does this translation happen or does a '.' occur?

          In your initial posting you wanted to access a function. Now it seems to be a member-variable or property or something?!? it should make no difference in my opinion but this way I can reproduce your problem more accurately.

          Best Soraltan

          1 Reply Last reply
          0
          • K Offline
            K Offline
            krisjobs
            wrote on last edited by
            #5

            Thank you for your reply.

            Your three assumptions are all correct, all is done within a class.

            As for the additional questions:

            1. No, it doesn't translate to ->, it remains as a point
            2. AFAIK it doesn't matter whether it's a member-variable or method/function
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              It might be an old Qt Creator problem (your version is pretty old), I would recommend updating to the latest version (currently 3.1) and try again.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Soraltan
                wrote on last edited by
                #7

                Yes I agree it should not matter. It is only that I can reproduce it better. Regardless it works in both cases for me: I can get code-completion for methods as well as for member-variables. I need to give an index to the at() function of course. There was a short moment when I thought I could reproduce your behaviour until I noted that I forgot to provide an index (e.g. at(0) instead of at()).

                Weird. Could you provide the class?!? Just so that I can test it with the class in question. But I must admit that I'm grasping for straws here. I have no real clue on what is going on.

                Btw: I have 2.4.1 32bit and I'm using Qt 4.8 (the latter should have no impact on code-completion though).

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Soraltan
                  wrote on last edited by
                  #8

                  Uff, I was not aware of how far QtCreator already got. A Bug that occurred somewhere between version 2.4 and 2.7 and was fixed later?!? Definitely worth a shot.

                  Regardless I will update mine, too! Let's see what has changed :-)

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andrep
                    wrote on last edited by
                    #9

                    Somewhat unrelated to the question, but related to the code: Why do you use a pointer to a QList object (as opposed to a plain QList object)?

                    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