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. How to write qDebug

How to write qDebug

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 5.6k 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.
  • L Offline
    L Offline
    liufanyansha
    wrote on last edited by
    #1

    the question is:
    *Using the function QObject::inherits(const char className), write qDebug statements testing if o inherits QObject and ValueObject.__
    my code is:
    widget.h
    @
    #ifndef WIDGET_H
    #define WIDGET_H

    #include<QtGui>
    #include <QtGui/QWidget>

    class Widget : public QWidget
    {
    Q_OBJECT
    Q_PROPERTY(int _value READ value WRITE setValue)
    public:
    Widget(int val =0, QWidget *parent = 0);
    void setValue(int val);
    int value();
    ~Widget();
    private:
    QLabel *label;
    int _value;
    };

    #endif // WIDGET_H
    @
    widget.cpp
    @
    #include "widget.h"

    Widget::Widget(int val, QWidget *parent)
    : QWidget(parent)
    {
    setValue(val);
    label=new QLabel("I am liufan",this);

    QHBoxLayout *mainLayout=new QHBoxLayout(this);
    
    mainLayout->addWidget(label);
    
    this->setLayout(mainLayout);
    
    this->setWindowTitle(tr("liufan"));
    

    }

    Widget::~Widget()
    {

    }

    void Widget::setValue(int val)
    {
    if(val == _value){
    return;
    }
    _value=val;
    }

    int Widget::value()
    {
    return _value;
    }

    @
    main.cpp
    @
    #include <QtGui/QApplication>
    #include "widget.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Widget w;
    qDebug("Value: %d = %d", w.value(), w.property("_value").toInt());
    w.setValue(42);
    qDebug("Value: %d = %d", w.value(), w.property("_value").toInt());
    w.setProperty("value", 11);
    qDebug("Value: %d = %d", w.value(), w.property("_value").toInt());
    w.show();

    return a.exec&#40;&#41;;
    

    }
    @
    how do I to write the qDebug statements testing

    good good study,day day up

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexKI
      wrote on last edited by
      #2

      see "qInstallMsgHandler":http://doc.qt.nokia.com/latest/qtglobal.html#qInstallMsgHandler

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        First: It would be helpful and polite, if you would provide us with the information what's going wrong. It's quite unrespectful to just dump a bunch of code and have the folks here figure out themselves what's happening.

        EDIT:
        And I forgot: Choose your topic carefully! "how to write qDebug" has absolutely nothing to do with your actual problem!

        Regarding your problem:

        try:

        @
        w.setProperty("_value", 11);
        @

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • L Offline
          L Offline
          liufanyansha
          wrote on last edited by
          #4

          I am very sorry.my english is so poor.next I will be carefully to start a discussion

          good good study,day day up

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            No problem with not so good English here, we're international, and not everybody speaks English well.

            Can you explain a bit more detailed, what your problem is/was? I suspect that output should be

            @
            0 = 0
            42 = 42
            11 = 11
            @

            But the last line reads 42 = 42. That's corrected by the fix I posted before.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • L Offline
              L Offline
              liufanyansha
              wrote on last edited by
              #6

              yes,It's that teaching me how to understand the "Properties".because I am a beginer,so I'm not so clear what and how to do.thank you for helping me.

              when commenting out the
              @
              //Q_PROPERTY(int _value READ value WRITE setValue)
              @
              I got
              @
              E:\study\qt\project\lianxi1-build-desktop\release\lianxi1.exe 启动中...
              Value: 0 = 0
              Value: 42 = 0
              Value: 42 = 0
              E:\study\qt\project\lianxi1-build-desktop\release\lianxi1.exe 退出, 代码: 0
              @

              but
              @
              Q_PROPERTY(int _value READ value WRITE setValue)
              @

              I got
              @
              E:\study\qt\project\lianxi1-build-desktop\release\lianxi1.exe 启动中...
              Value: 0 = 0
              Value: 42 = 42
              Value: 42 = 42
              E:\study\qt\project\lianxi1-build-desktop\release\lianxi1.exe 退出, 代码: 0
              @

              thank you remind me that be careful to start a discussion

              good good study,day day up

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                You made the simplest, yet very often most hardest to find error possible: Just a typo - you're missing the underscore before "value":

                @
                w.setProperty("value", 11); // wrong
                w.setProperty("_value", 11); // correct
                @

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  liufanyansha
                  wrote on last edited by
                  #8

                  thank you for your tips,I will be more careful to do it.
                  I am a chinise undergraduate,I hope I can be a successful programmer.

                  good good study,day day up

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    We all stumble over these tiny errors now and then :-)

                    Feel free to ask further questions - we do not bite (mostly :-) )

                    You might want to read http://www.catb.org/~esr/faqs/smart-questions.html some time, it has valuable hints on how to make a clever forum post.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    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