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. Making a checkbox checked
Forum Updated to NodeBB v4.3 + New Features

Making a checkbox checked

Scheduled Pinned Locked Moved General and Desktop
16 Posts 4 Posters 37.0k 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.
  • V Offline
    V Offline
    veeraps
    wrote on last edited by
    #6

    If you have void Robbie20::chkbox_client() method in Robbie20, why don't you call chkbox_client() within loadTextFile() method, which is also a method of Robbie20. Try to minimize the call in main and encapsulate them in your Concrete Class.

    How about showing Robbie20 Widget once you are done with loading Text File and changing check box state.

    @
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Robbie20 w;

        w.loadTextFile();
        w.chkbox_client();
    
        w.show();
    ....
    }
    

    @

    1 Reply Last reply
    0
    • V Offline
      V Offline
      veeraps
      wrote on last edited by
      #7

      Pardon me - actually it shouldn't make any difference whether you call setChecked(1) after show() call or before. Tried a sample code, to just confirm it, and it is working for me.

      Just added a CheckBox to the UI and added a method as you said and called the same after showing the widget, I see the checkbox is checked.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        roboterprogrammer
        wrote on last edited by
        #8

        hi,
        i will show screenshot when project finished, because we have to buy licence before using it on robot.

        ah the error was that i made the checkbox "not checkable"
        but now when it is checkable, the user can uncheck it. thats not mentioned.
        so i always have to
        make it checkable, then check/uncheck it and then make it again uncheckable ...

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #9

          setChecked() takes a boolean, not an integer; the call to isChecked() is unnecessary.

          You might post a small, compilable example that reproduces your problem.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            veeraps
            wrote on last edited by
            #10

            That's correct - setChecked() will work provided setCheckable() is enabled.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              roboterprogrammer
              wrote on last edited by
              #11

              thank u guys for helping.

              when i only make
              @ ui->chkbox_client->setChecked(1);@
              its checked, but its changable by hand - it mustn't and should be stable

              when

              @ ui->chkbox_client->setChecked(1);
              ui->chkbox_client->setCheckable(0);@
              its not checkable by hand, but the check is removed

              any ideas?

              1 Reply Last reply
              0
              • V Offline
                V Offline
                veeraps
                wrote on last edited by
                #12

                The additional effort is whenever you want to change the state (setCheckable()), you need to first change the check box as checkable and then set the new state and set the checkable flag to false.

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

                  Or just use checkbox::setEnabled(false). It will gray the widget out, though. This probably can be overridden.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    roboterprogrammer
                    wrote on last edited by
                    #14

                    hi,
                    now i have a strange problem

                    in main.cpp
                    @
                    w.chkbox_client;@

                    works great and set the box checked.

                    but also in main.cpp,
                    @
                    QObject::connect(st.socket,SIGNAL(connected()), &w, SLOT(chkbox_client()));@
                    doesn't work, even i see there is a signal connected emittet.

                    i can see it because in the tcpconnect class, i put this signals out with qdebug, so i see exactly its connected.

                    and in my main.cpp
                    i have this:@
                    QObject::connect(st.socket,SIGNAL(readyRead()), &w, SLOT(loadTextFile() ) );@
                    and this works great.

                    thankful for any hints

                    PS:
                    btw st is an object made of the class qtcpsocket, and there its made with socket = new QTcpSocket(this);
                    and there i have piped the connection signal out@
                    connect(socket,SIGNAL(connected()), this, SLOT(connected()));@

                    where connected is a method who tells the connection via qdebug to me

                    general second question:
                    is the main.cpp the right place for those - inter class connections?

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

                      Does st.socked return a pointer?

                      (Z(:^

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        roboterprogrammer
                        wrote on last edited by
                        #16

                        hi,
                        i think so,
                        because no errors when compiling, and when i do with
                        &st.socket
                        there is an error
                        @C:\Dokumente und Einstellungen\loetrobo\Robbie20-build-desktop-Qt_4_8_0_for_Desktop_-_MinGW__Qt_SDK__Debug..\Robbie20\main.cpp:19: error: no matching function for call to 'QObject::connect(QTcpSocket**, const char*, Robbie20*, const char*)'@
                        looking like a double pointer so without &
                        it should be normal pointer

                        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