Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Trouble with connect()...

    General and Desktop
    4
    7
    434
    Loading More Posts
    • 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
      AlexanderAlexander last edited by AlexanderAlexander

      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 Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        @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 Reply Quote 7
        • sierdzio
          sierdzio Moderators last edited by

          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 Reply Quote 7
          • A
            AlexanderAlexander @sierdzio last edited by

            @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

            jsulm 1 Reply Last reply Reply Quote 0
            • Christian Ehrlicher
              Christian Ehrlicher Lifetime Qt Champion last edited by

              @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 has to stay free or it will die.

              1 Reply Last reply Reply Quote 4
              • jsulm
                jsulm Lifetime Qt Champion @AlexanderAlexander last edited by

                @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 Reply Quote 3
                • A
                  AlexanderAlexander last edited by

                  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 Reply Quote 0
                  • First post
                    Last post