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]setText not working
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]setText not working

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 3.9k Views 2 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
    manny
    wrote on last edited by manny
    #1

    hello,

    I have a rally noob question here, and its that setText is not working. for example"

        connect(pushButton1, SIGNAL(clicked()), 
                      lineEdit, SLOT(setText(QString("1"))));
    

    it then underlines the line red saying that it expectd a semicolon but got a parenthesis. I checked all the brackets and they seem to line up, and it happens to be the "1" in the setText that causes the problem. any help?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      You've got a wrong idea of how a signal-slot connection works. The slot parameter is taken from a matching signal argument if it has one, not from you directly.

      For example if there is a signal somethingHappened(int foo) then a slot doSomething(int bar) will receive the parameter from the signal: connect(senderObject, SIGNAL(somethingHappened(int)), receiverObject, SLOT(doSomething(int))).

      So in short you can't pass an argument (QString("1")) at a connection site.

      On the other hand there are a few more connect()overloads that don't take SIGNAL and SLOT macros. For example you can connect a lambda like this:

      connect(pushButton1, &QPushButton::clicked, [=]{ lineEdit->setText(QString("1"); });
      
      1 Reply Last reply
      2
      • M Offline
        M Offline
        manny
        wrote on last edited by manny
        #3

        but isn't setText a public slot of QlineEdit

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          but isn't setText a public slot of QlineEdit

          Yes, a slot that takes a string parameter. The clicked() signal passes no parameters so there's no way to connect these two.
          As I said the SLOT macro does not take parameters from you. It takes it from the signal you connect it to, so they need to match.

          1 Reply Last reply
          1
          • M Offline
            M Offline
            manny
            wrote on last edited by manny
            #5

            ok, i think i understand now.

            so, is ther any pushbutton signal that has a qstring parameter, or will o have to make one my self, and then use the diplaytext function to display the text

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              is there any pushbutton signal that has a qstring parameter

              No, buttons don't generate text. They generate clicks.

              So you can either subclass a button and give it a signal that generates text (but that is really messed up conceptually) or simply connect the click to something that doesn't require a parameter (like the lambda example in my previous post).

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

                thanks for the reply, really helps

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  manny
                  wrote on last edited by manny
                  #8
                  This post is deleted!
                  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