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] Read checkbox checked state?
QtWS25 Last Chance

[SOLVED] Read checkbox checked state?

Scheduled Pinned Locked Moved General and Desktop
23 Posts 3 Posters 13.8k Views
  • 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.
  • J Offline
    J Offline
    jediengineer
    wrote on last edited by
    #14

    Ok, here's a screenshot of the error:

    !http://tinypic.com/r/2vsoups/8()!

    Sorry, it's the first place I found to host the picture...

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #15

      [quote author="jediengineer" date="1392386177"]Ok, here's a screenshot of the error:

      !http://tinypic.com/r/2vsoups/8()!

      Sorry, it's the first place I found to host the picture... [/quote]Your compiler doesn't know what a QQuickItem is, and doesn't realize that it can take part in signal-slot connections. To inform your compiler,
      @#include <QQuickItem>@

      By the way, the "is required here" message is only an extra note that comes after the actual error message. The real error message (which is the message you'd use to find the root of the problem) is at the 1st red exclamation mark.

      [quote author="t3685" date="1392361043"]the clicked signal is no more or less encapsulated than the custom signal you defined in your button. it is just as accessible to everyone else. since you are not using it with any parameters or I must have looked over out it felt a little redundant to me :-). any case good luck! [/quote]I meant encapsulating the buttons/checkboxes away from C++ code. :) The OP's slot is a C++ function.

      Granted, it's not very "hidden" at the moment because the signal name is "buttonClicked_enable()", but that's a different matter.

      [quote author="jediengineer" date="1392378240"]T3685, in my case, I have about 23 buttons I'm assigning to slots. How would you differentiate them all, based on what you said?[/quote]t3685 meant that you can call your C++ slots directly from QML, without adding the extra "buttonClicked_enable()" signal. It's the "shorter method" that I hinted at in http://qt-project.org/forums/viewthread/37907/

      If you're eager to investigate it, that method involves inserting your C++ object into QML as a "context property":http://qt-project.org/doc/qt-5/qtqml-cppintegration-contextproperties.html. However, I still recommend that you leave context properties for later, and focus on mastering the signal-slot method first. The latter is much more useful for Qt programming overall.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jediengineer
        wrote on last edited by
        #16

        Holy Crap, JKSH, I can't believe it was as simple as a header file... I'm not sure how I didn't catch that, maybe it's because QQuickView highlighted itself in green, so I assumed it was recognized... Well, I feel dumb. But thanks for pointing that out...

        I won't bother with the context property for now unless this runs at a snail's pace, which I suspect it won't. Thanks again, you've given me an insight to how some of this stuff works, and I appreciate it! Now I've got a little reading to do on checkbox signals... Thanks a million!!

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jediengineer
          wrote on last edited by
          #17

          Ok, one last question about this - I think I've got a destructor issue... now I'm not too sure of myself with destructors, but I've tried a few different ways to fix this. Everything compiles fine except the class - I get a "undefined reference to 'vtable for TLA_Funcs' " message when I compile. I know this has something to do with the destructor, and I'm trying to figure it out, and I've even tried several recommended methods for fixing it, posted on stackoverflow... but nothing seems to help. Any ideas? Again, here's my class, and it's in my custom header file...

          @class TLA_Funcs : public QObject {

          Q_OBJECT
          

          public slots:
          void sys_enable(){return;} // enable left, right, or both inverters
          void sys_inhibit(){return;} // inhibit left, right, or both inverters
          void sys_hard_inhibit(){return;} // inhibit system via main inhibit line
          void sys_disable(){return;} // disable entire system
          void sys_autoupdate(){return;} // enables or disables autoupdate
          void sys_reset(){return;} // resets analog inverter controller
          void sys_observe(){return;} // forces observation mode
          void sys_dac_test(){return;} // performs DAC self test
          void sys_reset_dac(){return;} // resets the DAC
          void sys_read_adc(){return;} // reads ADC inputs
          void sys_read_mux(){return;} // reads MUX inputs
          void sys_poll(){return;} // Quick ADC and MUX poll
          void sys_set_voltage(){return;} // sets output voltage percent
          void sys_set_current(){return;} // sets output current percent
          void sys_set_power(){return;} // sets output power percent
          void sys_set_all(){return;} // sets all output controls simultaneously by percent
          void sys_save_dac_settings(){return;} // save all dac settings
          void sys_delete_dac_settings(){return;} // delete saved dac settings
          void sys_restore_dac_settings(){return;} // restores saved settings from memory
          void sys_cpu_reset(){return;} // resets CPU
          void sys_cpu_halt(){return;} // halts cpu
          void sys_self_check(){return;} // performs full system check.
          void sys_adc_test(){return;} // ADC test

          void sys_left_inv(){left_inv = !left_inv;}
          void sys_right_inv(){right_inv = !right_inv;}
          void sys_step(){step = !step;}
          void sys_fine_step(){fine = !fine;}
          void sys_step_up(){up = !up;}
          void sys_spec_mux(){specific_mux = !specific_mux;}
          void sys_spec_adc(){specific_adc = !specific_adc;}
          

          protected:
          bool left_inv;
          bool right_inv;
          bool step;
          bool fine;
          bool up;
          bool specific_mux;
          bool specific_adc;
          };@

          I've tried a bunch of different methods of constructing and destructing, but nothing seems to work. Any ideas?

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #18

            [quote]I get a “undefined reference to ‘vtable for TLA_Funcs’ “[/quote]No destructors involved here.

            This error can be cause by a few different things. In your case, you just have an outdated Makefile. You need to generate a new one if you add "Q_OBJECT" to any class:

            Build -> Clean Project _____ (not strictly necessary, but I do it just in case)

            Build -> Run qmake

            Build -> Build Project _____

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jediengineer
              wrote on last edited by
              #19

              err... Nope, that wasn't it. Same error as before. Still pointing to my class with the "undefined reference to 'vtable for TLA' " error message.

              I'm fiddling with it, trying to understand this. This is quite a change from what I'm used to doing with embedded DSP processors...

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #20

                [quote author="jediengineer" date="1392503915"]err... Nope, that wasn't it. Same error as before. Still pointing to my class with the "undefined reference to 'vtable for TLA' " error message.

                I'm fiddling with it, trying to understand this. This is quite a change from what I'm used to doing with embedded DSP processors...[/quote]Another cause of this error is if you declared TLA_Funcs in a .cpp file.

                Qt uses a "code generator":http://qt-project.org/doc/qt-5/why-moc.html to support signals+slots and many other features. The code generator (called 'moc', for "Meta-Object Compiler") requires all QObject declarations to be put in an header files.

                Solution: Move your TLA_Funcs declaration to a .h file (Remember to run qmake afterwards)

                P.S. Add a constructor to your class to initialize all its variables to a default value. If you don't do this, they will contain random garbage values.
                @
                public:
                TLA_Funcs(QObject *parent = 0) : QObject(parent)
                {
                // Initialize all your member variables here
                }
                @
                P.P.S. Use "private", not "protected". "Protected" is for subclassing.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jediengineer
                  wrote on last edited by
                  #21

                  JKSH - thanks, I had already tried that but it didn't work.. :-(

                  HOWEVER, I did the following, which I hadn't before: I went to File->New File or Project->C++->C++ Class to create a new class, versus just making a class in my header file. Once completed, I transferred my class to the new file and lo and behold, it compiled. I tried to do a test run, and it gave me a connection error, which I'm still currently working on...

                  QObject::connect: Cannot connect (null)::buttonClicked_enable() to TLA_Funcs::sys_enable()

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jediengineer
                    wrote on last edited by
                    #22

                    Just to be clear, my code is now this:

                    header file:

                    @class TLA_Funcs : public QObject
                    {
                    Q_OBJECT
                    public:
                    explicit TLA_Funcs(QObject *parent = 0);
                    signals:

                    public slots:
                    Q_INVOKABLE void sys_enable(){return;}

                    . . .
                    };@

                    .cpp file:

                    @#include " ... "

                    TLA_Funcs::TLA_Funcs(QObject *parent) :
                    QObject(parent)
                    {
                    }

                    int main (int argc, char*argv[]) {

                    QGuiApplication app(argc, argv);
                    
                    QQuickView *view = new QQuickView(QUrl("main.qml"));                   
                    view->show(); 
                    
                    QQuickItem *item = view->rootObject();                               
                    
                    TLA_Funcs *funcs = new TLA_Funcs();      
                                              
                    // connect button signals to their slots:
                    QObject::connect(item, SIGNAL(buttonClicked_enable()), funcs, SLOT(sys_enable()));
                    

                    return 0;
                    }@

                    QML:

                    @Rectangle {
                    id: main
                    width: 800
                    height: 600
                    color: "#abcfe9"
                    border.width: 4
                    border.color: "#000000"

                    signal buttonClicked_enable
                    
                    Button {
                        id: autoupdate
                        x: 628
                        y: 55
                        text: "AutoUpdate"
                        onClicked:buttonClicked_enable()
                    

                    }@

                    It builds fine, but when I run it, I get the error:

                    "QObject::connect: Cannot connect (null)::buttonClicked_enable() to TLA_Funcs::sys_enable()"

                    I tried using @onClicked:main.buttonClicked_enable()@
                    to connect... I also tried using your method from the previous post you suggested:

                    @onClicked:{
                    buttonClicked_enable()
                    TLA_Funcs.sys_enable()
                    }@

                    but it still gives me the same error. Did I miss something? Do I need to list my signals under "signals" in the class? if so, would they be posted the same way as in the QML code?

                    @
                    signals:
                    buttonClicked_enable()@

                    Please advise, this is tormenting me because I'm getting the feeling that it is one of those things that's staring me in the face... only this time it's laughing at me...

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jediengineer
                      wrote on last edited by
                      #23

                      Cancel that last request. Problem solved. There was an issue with the .pro file. I have since created a new project, copied my code into it, and it works correctly!!! Thanks all, especially JKSH, for all the help with affording me an opportunity to learn!!!

                      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