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. [solved],Issue with QVector
Forum Updated to NodeBB v4.3 + New Features

[solved],Issue with QVector

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.3k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    mcpolandc
    wrote on last edited by
    #1

    I am coming at this from 2 different angles but having no success with either. What I am trying to do is have a vector of 'ParsableTextEdit' which is my own type that is derived from QTextEdit. I am implementing a tab system using QTabWidget. So I have a pointer called 'currentTab', this is used to point to elements in the vector to make it the current one.

    The first approach was using pointers like so:

    @QVector<ParsableTextEdit *> vec;@

    and appending like so:

    @vec.append(new ParsableTextEdit);@

    Then when I want to make any of them the current one, I do this:

    @currentTab = vec[index];@

    This causes no errors and makes sense to me but I know that currentTab is not referencing the right ParsableTextEdit when I switch away from the first one because I have connected the textChanged() signal to a slot like so:

    @connect(currentTab,SIGNAL(textChanged()),this,SLOT(SetModified()));@

    and it doesn't get fired when I switch to another index in the vector. All this really does is adds an asterisk to the tab name so I know it has been modified. It works for the first element in the vector but no others.

    The other approach I took was making the vector elements plain objects like this:

    @QVector<ParsableTextEdit> vec;@

    Then I would do this when I am adding a new one:

    @Parsable temp = ParsableTextEdit();
    vec.append(temp);
    currentTab = &vec[vec.count -1];@

    This then gives me errors like:

    @QTextEdit::QTextEdit(const QTextEdit&) is private
    Q_DISABLE_COPY(QTextEdit)@

    I have no idea what that means :/

    If anyone knows what is causing this, I would really appreciate the help. Please ask if more information is needed.

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      QObject and QObject derived classes cannot be copied. You can find a more complete explication on why it is like that in QObject's documentation.

      Why are you not using QTabWidget::currentIndex or QTabWidget::currentWidget to retrieve the current widget ?

      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
      • M Offline
        M Offline
        mcpolandc
        wrote on last edited by
        #3

        I think the reason I went for the vector to keep track of my tabs rather than that was because the currentWidget function obviously returns a QWidget. I want to have a ParsableTextEdit returned.

        Am I being silly here? Do I need to have my ParsableTextEdit within a QWidget that is appended to the QTabWidget? I know it too is derived from QWidget but I shouldn't cast down?

        Thanks for your reply bro

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          But you are getting a ParsableTextEdit. You just need to cast the returned pointer using qobject_cast. No need to have any dummy container widget

          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
          • M Offline
            M Offline
            mcpolandc
            wrote on last edited by
            #5

            Yeah man, a little read at at the QTabWidget documentation kinda showed me how stupid I was being. Still in the process of building it that way but will mark this thread as solved soon.

            Thanks for your help ;)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcpolandc
              wrote on last edited by
              #6

              Quick question:

              I am using:

              @currentTab = qobject_cast<ParsableTextEdit *>(tabs->currentWidget());@

              to pass a pointer to my currentTab pointer. The only reason I am doing this is because I am connecting currentTabs textChanged() signal to my SLOT.

              Would you suggest I am going about it wrong?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mcpolandc
                wrote on last edited by
                #7

                Ok, solved... I should not be allowed near code haha

                The pointer was pointing to the right thing all along. My signal and slot were the problem. It connection needs to be reestablished if pointing to another object.

                Thank you for your help. Much obliged!

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You only need to establish the connection once for each widget (unless you have a good reason to disconnect)

                  You're welcome !

                  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

                  • Login

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