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. Trouble with connect()...
Forum Updated to NodeBB v4.3 + New Features

Trouble with connect()...

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 953 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.
  • A Offline
    A Offline
    AlexanderAlexander
    wrote on last edited by AlexanderAlexander
    #1

    I wish to connect/sync the vertical scroll bars of 2 plain text edits together like so in C++:

    connect(this->textEdit_T->verticalScrollBar, SIGNAL(valueChanged(int)), this->textEdit_S->verticalScrollBar, SLOT(setValue(int)));
    connect(this->textEdit_S->verticalScrollBar, SIGNAL(valueChanged(int)), this->textEdit_T->verticalScrollBar, SLOT(setValue(int)));
    

    However, I get this error:

    error C3867: 'QAbstractScrollArea::verticalScrollBar': non-standard syntax; use '&' to create a pointer to member

    And when I add "&"' to the senders I get this error:

    error C2276: '&': illegal operation on bound member function expression

    My apologies, this is probobaly a very simple mix up but I am a little confused.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @alexanderalexander said in Trouble with connect()...:

      this->textEdit_T->verticalScrollBar

      This is a function so it has to end with (), thus:

      this->textEdit_T->verticalScrollBar()
      

      (Z(:^

      1 Reply Last reply
      7
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        Also, I strongly recommend using new signal-slot connection syntax, it will avoid you many troubles! https://doc.qt.io/qt-5/signalsandslots-syntaxes.html

        (Z(:^

        A 1 Reply Last reply
        7
        • sierdzioS sierdzio

          Also, I strongly recommend using new signal-slot connection syntax, it will avoid you many troubles! https://doc.qt.io/qt-5/signalsandslots-syntaxes.html

          A Offline
          A Offline
          AlexanderAlexander
          wrote on last edited by
          #4

          @sierdzio
          My apologies, I meant to include this in my example above:

          connect(this->textEdit_T->verticalScrollBar(), SIGNAL(valueChanged(int)), this->textEdit_S->verticalScrollBar(), SLOT(setValue(int)));
          	connect(this->textEdit_S->verticalScrollBar(), SIGNAL(valueChanged(int)), this->textEdit_T->verticalScrollBar(), SLOT(setValue(int)));
          

          This ^ causes another error, telling me that there is no overloaded function (of the class I call this in)
          that matches the argument list. When I try to compile it then tells me this:

          Error C2664 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const': cannot convert argument 1 from 'QScrollBar *' to 'const QObject *' KOALA C:\WorkSpace\KOALA\EPRateMod.cxx 85

          Note: I am including QObject

          jsulmJ 1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @alexanderalexander said in Trouble with connect()...:

            cannot convert argument 1 from 'QScrollBar *' to 'const QObject *'

            You forgot to include QScrollBar header file. And please don't use old signals/slot syntax.

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

            1 Reply Last reply
            4
            • A AlexanderAlexander

              @sierdzio
              My apologies, I meant to include this in my example above:

              connect(this->textEdit_T->verticalScrollBar(), SIGNAL(valueChanged(int)), this->textEdit_S->verticalScrollBar(), SLOT(setValue(int)));
              	connect(this->textEdit_S->verticalScrollBar(), SIGNAL(valueChanged(int)), this->textEdit_T->verticalScrollBar(), SLOT(setValue(int)));
              

              This ^ causes another error, telling me that there is no overloaded function (of the class I call this in)
              that matches the argument list. When I try to compile it then tells me this:

              Error C2664 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const': cannot convert argument 1 from 'QScrollBar *' to 'const QObject *' KOALA C:\WorkSpace\KOALA\EPRateMod.cxx 85

              Note: I am including QObject

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

              @alexanderalexander The error message is talking about connect() with different parameters than what you have in these two lines - are you sure the error message comes from one of these lines?
              You really should try new connect syntax as @sierdzio suggested.

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

              1 Reply Last reply
              3
              • A Offline
                A Offline
                AlexanderAlexander
                wrote on last edited by
                #7

                Thanks for all the help guys, figured it was just a stupid mistake like that. Just wanted to get this working and then I'll take everyone's advice and use the newer signal/slot syntax.

                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