Qt Forum

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

    How to write qDebug

    General and Desktop
    3
    9
    5011
    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.
    • L
      liufanyansha last edited by

      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 Reply Quote 0
      • A
        alexKI last edited by

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

        1 Reply Last reply Reply Quote 0
        • G
          goetz last edited by

          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 Reply Quote 0
          • L
            liufanyansha last edited by

            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 Reply Quote 0
            • G
              goetz last edited by

              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 Reply Quote 0
              • L
                liufanyansha last edited by

                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 Reply Quote 0
                • G
                  goetz last edited by

                  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 Reply Quote 0
                  • L
                    liufanyansha last edited by

                    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 Reply Quote 0
                    • G
                      goetz last edited by

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