Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How can I send output to a widget
Forum Updated to NodeBB v4.3 + New Features

How can I send output to a widget

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
23 Posts 6 Posters 9.3k Views 4 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.
  • D DocDJ

    @mostefa Still does not work. NO errors, but no results in answerbox.

    M Offline
    M Offline
    mostefa
    wrote on last edited by
    #13

    @DocDJ said in How can I send output to a widget:

    @mostefa Still does not work. NO errors, but no results in answerbox.

    Your signal is not ok, your answer does not contain the result of any operation

    Your signal

    textChanged(const QString &) does not exist for QTextEdit

    Have a look at available signals:

    http://doc.qt.io/qt-4.8/qtextedit.html#signals

    You have to use

    textChanged();

    So i changed your code and multiplication work for me:

    Your header:

    #ifndef djdialog1_H
    #define djdialog1_H
    
    #include <QDialog>
    #include "ui_djdialog1.h"
    
    
    // add namespace Ui to your .H
    namespace Ui {
    class djdialog1;
    }
    class djdialog1 : public QDialog, public Ui::djdialog1
    {
        Q_OBJECT
    public:
        djdialog1(QWidget *parent = 0);
    
    private slots:
        void onInt1boxTextChanged();// slot without arg
        void onInt2boxTextChanged();// slot without arg
    
    you don't need an arg ui->int1box , ui->int2box will be ok
    
        void onGoButtonclicked();//just changed the name of the slot
    
    private:
        Ui::djdialog1 *ui;//Add uiVar member
    };
    #endif
    
    #include <QtGui>
    #include "djdialog1.h"
    #include <sstream>
    #include <string>
    #include <QTextEdit>
    
    int int1, int2, answer;
    djdialog1::djdialog1(QWidget *parent)
        : QDialog(parent),
          ui(new Ui::djdialog1)// initialize ui
    {
        ui->setupUi(this);//setup Ui
        connect(ui->int1box, SIGNAL(textChanged()),
                this, SLOT(onInt1boxTextChanged()));
        connect(ui->int2box, SIGNAL(textChanged()),
                this, SLOT(onInt2boxTextChanged()));
        connect(ui->GoButton, SIGNAL(clicked()), this, SLOT(onGoButtonclicked()));
    }
    void djdialog1::onGoButtonclicked()
    {
        QString qreply;
    
        answer = int1*int2;// your mathematic operation here
        qreply=QString::number(answer);
        ui->answerbox->setText(qreply);//anserbox from ui
    }
    void djdialog1::onInt1boxTextChanged()
    {bool ok;
        int1 = ui->int1box->toPlainText().toInt(&ok,10);
    }
    void djdialog1::onInt2boxTextChanged()
    {bool ok;
        int2 = ui->int2box->toPlainText().toInt(&ok,10);
    }
    

    Hope this can help!

    D 1 Reply Last reply
    0
    • M mostefa

      @DocDJ said in How can I send output to a widget:

      @mostefa Still does not work. NO errors, but no results in answerbox.

      Your signal is not ok, your answer does not contain the result of any operation

      Your signal

      textChanged(const QString &) does not exist for QTextEdit

      Have a look at available signals:

      http://doc.qt.io/qt-4.8/qtextedit.html#signals

      You have to use

      textChanged();

      So i changed your code and multiplication work for me:

      Your header:

      #ifndef djdialog1_H
      #define djdialog1_H
      
      #include <QDialog>
      #include "ui_djdialog1.h"
      
      
      // add namespace Ui to your .H
      namespace Ui {
      class djdialog1;
      }
      class djdialog1 : public QDialog, public Ui::djdialog1
      {
          Q_OBJECT
      public:
          djdialog1(QWidget *parent = 0);
      
      private slots:
          void onInt1boxTextChanged();// slot without arg
          void onInt2boxTextChanged();// slot without arg
      
      you don't need an arg ui->int1box , ui->int2box will be ok
      
          void onGoButtonclicked();//just changed the name of the slot
      
      private:
          Ui::djdialog1 *ui;//Add uiVar member
      };
      #endif
      
      #include <QtGui>
      #include "djdialog1.h"
      #include <sstream>
      #include <string>
      #include <QTextEdit>
      
      int int1, int2, answer;
      djdialog1::djdialog1(QWidget *parent)
          : QDialog(parent),
            ui(new Ui::djdialog1)// initialize ui
      {
          ui->setupUi(this);//setup Ui
          connect(ui->int1box, SIGNAL(textChanged()),
                  this, SLOT(onInt1boxTextChanged()));
          connect(ui->int2box, SIGNAL(textChanged()),
                  this, SLOT(onInt2boxTextChanged()));
          connect(ui->GoButton, SIGNAL(clicked()), this, SLOT(onGoButtonclicked()));
      }
      void djdialog1::onGoButtonclicked()
      {
          QString qreply;
      
          answer = int1*int2;// your mathematic operation here
          qreply=QString::number(answer);
          ui->answerbox->setText(qreply);//anserbox from ui
      }
      void djdialog1::onInt1boxTextChanged()
      {bool ok;
          int1 = ui->int1box->toPlainText().toInt(&ok,10);
      }
      void djdialog1::onInt2boxTextChanged()
      {bool ok;
          int2 = ui->int2box->toPlainText().toInt(&ok,10);
      }
      

      Hope this can help!

      D Offline
      D Offline
      DocDJ
      wrote on last edited by
      #14

      @mostefa It still does not produce output. The only difference I can see between your version and mine is that my slot names have the _ character in them (e.g.; on_GoButton_textChanged). Could this make a difference? There are no compiler error or warning messages.

      jsulmJ M 2 Replies Last reply
      0
      • D DocDJ

        @mostefa It still does not produce output. The only difference I can see between your version and mine is that my slot names have the _ character in them (e.g.; on_GoButton_textChanged). Could this make a difference? There are no compiler error or warning messages.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #15

        @DocDJ Underscores doesn't matter.
        You should really check whether all connect calls succeed.
        Can you post your header and cpp file?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply
        0
        • D DocDJ

          @mostefa It still does not produce output. The only difference I can see between your version and mine is that my slot names have the _ character in them (e.g.; on_GoButton_textChanged). Could this make a difference? There are no compiler error or warning messages.

          M Offline
          M Offline
          mostefa
          wrote on last edited by
          #16

          @DocDJ said in How can I send output to a widget:

          @mostefa It still does not produce output. The only difference I can see between your version and mine is that my slot names have the _ character in them (e.g.; on_GoButton_textChanged). Could this make a difference? There are no compiler error or warning messages.

          I tested the code beofre i posted here and it work, looks like there is something you're doing wrong

          You said :
          There are no compiler error or warning messages.

          Ok

          But is there any output (errors/informations) when your app is running?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DocDJ
            wrote on last edited by
            #17

            Sorry I couldn't reply sooner. There are no error messages (compiling or running) , no output of any kind and my GUI window just sits there.

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @DocDJ Underscores doesn't matter.
              You should really check whether all connect calls succeed.
              Can you post your header and cpp file?

              D Offline
              D Offline
              DocDJ
              wrote on last edited by
              #18

              @jsulm I have modified my code to be exactly like that posted by @mostefa

              M 1 Reply Last reply
              0
              • D DocDJ

                @jsulm I have modified my code to be exactly like that posted by @mostefa

                M Offline
                M Offline
                mostefa
                wrote on last edited by
                #19

                @DocDJ said in How can I send output to a widget:

                @jsulm I have modified my code to be exactly like that posted by @mostefa

                Could you share with us the content of your .ui file?

                D 1 Reply Last reply
                0
                • M mostefa

                  @DocDJ said in How can I send output to a widget:

                  @jsulm I have modified my code to be exactly like that posted by @mostefa

                  Could you share with us the content of your .ui file?

                  D Offline
                  D Offline
                  DocDJ
                  wrote on last edited by
                  #20

                  @mostefa Here is my .ui file:
                  <?xml version="1.0" encoding="UTF-8"?>
                  <ui version="4.0">
                  <class>djdialog1</class>
                  <widget class="QDialog" name="djdialog1">
                  <property name="windowModality">
                  <enum>Qt::ApplicationModal</enum>
                  </property>
                  <property name="geometry">
                  <rect>
                  <x>0</x>
                  <y>0</y>
                  <width>334</width>
                  <height>300</height>
                  </rect>
                  </property>
                  <property name="windowTitle">
                  <string>DJs-Dialog</string>
                  </property>
                  <widget class="QTextEdit" name="int1box">
                  <property name="geometry">
                  <rect>
                  <x>73</x>
                  <y>10</y>
                  <width>61</width>
                  <height>41</height>
                  </rect>
                  </property>
                  <property name="toolTip">
                  <string>int 1 here</string>
                  </property>
                  </widget>
                  <widget class="QTextEdit" name="int2box">
                  <property name="geometry">
                  <rect>
                  <x>73</x>
                  <y>70</y>
                  <width>61</width>
                  <height>41</height>
                  </rect>
                  </property>
                  </widget>
                  <widget class="QLabel" name="label">
                  <property name="geometry">
                  <rect>
                  <x>160</x>
                  <y>10</y>
                  <width>60</width>
                  <height>31</height>
                  </rect>
                  </property>
                  <property name="text">
                  <string>first int</string>
                  </property>
                  <property name="alignment">
                  <set>Qt::AlignCenter</set>
                  </property>
                  </widget>
                  <widget class="QLabel" name="label_2">
                  <property name="geometry">
                  <rect>
                  <x>160</x>
                  <y>70</y>
                  <width>91</width>
                  <height>21</height>
                  </rect>
                  </property>
                  <property name="text">
                  <string>second int</string>
                  </property>
                  <property name="alignment">
                  <set>Qt::AlignCenter</set>
                  </property>
                  </widget>
                  <widget class="QTextEdit" name="answerbox">
                  <property name="geometry">
                  <rect>
                  <x>70</x>
                  <y>150</y>
                  <width>104</width>
                  <height>41</height>
                  </rect>
                  </property>
                  </widget>
                  <widget class="QLabel" name="label_3">
                  <property name="geometry">
                  <rect>
                  <x>0</x>
                  <y>80</y>
                  <width>60</width>
                  <height>31</height>
                  </rect>
                  </property>
                  <property name="styleSheet">
                  <string notr="true">color: rgb(0, 0, 255);
                  font: 16pt "Bitstream Charter";</string>
                  </property>
                  <property name="text">
                  <string>+</string>
                  </property>
                  <property name="alignment">
                  <set>Qt::AlignCenter</set>
                  </property>
                  </widget>
                  <widget class="QPushButton" name="GoButton">
                  <property name="geometry">
                  <rect>
                  <x>90</x>
                  <y>230</y>
                  <width>87</width>
                  <height>27</height>
                  </rect>
                  </property>
                  <property name="text">
                  <string>Compute</string>
                  </property>
                  </widget>
                  <widget class="QPushButton" name="clearbutton">
                  <property name="geometry">
                  <rect>
                  <x>200</x>
                  <y>230</y>
                  <width>87</width>
                  <height>27</height>
                  </rect>
                  </property>
                  <property name="text">
                  <string>Clear data</string>
                  </property>
                  </widget>
                  </widget>
                  <resources/>
                  <connections/>
                  </ui>

                  M 1 Reply Last reply
                  0
                  • D DocDJ

                    @mostefa Here is my .ui file:
                    <?xml version="1.0" encoding="UTF-8"?>
                    <ui version="4.0">
                    <class>djdialog1</class>
                    <widget class="QDialog" name="djdialog1">
                    <property name="windowModality">
                    <enum>Qt::ApplicationModal</enum>
                    </property>
                    <property name="geometry">
                    <rect>
                    <x>0</x>
                    <y>0</y>
                    <width>334</width>
                    <height>300</height>
                    </rect>
                    </property>
                    <property name="windowTitle">
                    <string>DJs-Dialog</string>
                    </property>
                    <widget class="QTextEdit" name="int1box">
                    <property name="geometry">
                    <rect>
                    <x>73</x>
                    <y>10</y>
                    <width>61</width>
                    <height>41</height>
                    </rect>
                    </property>
                    <property name="toolTip">
                    <string>int 1 here</string>
                    </property>
                    </widget>
                    <widget class="QTextEdit" name="int2box">
                    <property name="geometry">
                    <rect>
                    <x>73</x>
                    <y>70</y>
                    <width>61</width>
                    <height>41</height>
                    </rect>
                    </property>
                    </widget>
                    <widget class="QLabel" name="label">
                    <property name="geometry">
                    <rect>
                    <x>160</x>
                    <y>10</y>
                    <width>60</width>
                    <height>31</height>
                    </rect>
                    </property>
                    <property name="text">
                    <string>first int</string>
                    </property>
                    <property name="alignment">
                    <set>Qt::AlignCenter</set>
                    </property>
                    </widget>
                    <widget class="QLabel" name="label_2">
                    <property name="geometry">
                    <rect>
                    <x>160</x>
                    <y>70</y>
                    <width>91</width>
                    <height>21</height>
                    </rect>
                    </property>
                    <property name="text">
                    <string>second int</string>
                    </property>
                    <property name="alignment">
                    <set>Qt::AlignCenter</set>
                    </property>
                    </widget>
                    <widget class="QTextEdit" name="answerbox">
                    <property name="geometry">
                    <rect>
                    <x>70</x>
                    <y>150</y>
                    <width>104</width>
                    <height>41</height>
                    </rect>
                    </property>
                    </widget>
                    <widget class="QLabel" name="label_3">
                    <property name="geometry">
                    <rect>
                    <x>0</x>
                    <y>80</y>
                    <width>60</width>
                    <height>31</height>
                    </rect>
                    </property>
                    <property name="styleSheet">
                    <string notr="true">color: rgb(0, 0, 255);
                    font: 16pt "Bitstream Charter";</string>
                    </property>
                    <property name="text">
                    <string>+</string>
                    </property>
                    <property name="alignment">
                    <set>Qt::AlignCenter</set>
                    </property>
                    </widget>
                    <widget class="QPushButton" name="GoButton">
                    <property name="geometry">
                    <rect>
                    <x>90</x>
                    <y>230</y>
                    <width>87</width>
                    <height>27</height>
                    </rect>
                    </property>
                    <property name="text">
                    <string>Compute</string>
                    </property>
                    </widget>
                    <widget class="QPushButton" name="clearbutton">
                    <property name="geometry">
                    <rect>
                    <x>200</x>
                    <y>230</y>
                    <width>87</width>
                    <height>27</height>
                    </rect>
                    </property>
                    <property name="text">
                    <string>Clear data</string>
                    </property>
                    </widget>
                    </widget>
                    <resources/>
                    <connections/>
                    </ui>

                    M Offline
                    M Offline
                    mostefa
                    wrote on last edited by mostefa
                    #21

                    @DocDJ said in How can I send output to a widget:

                    @mostefa Here is my .ui file:
                    <?xml version="1.0" encoding="UTF-8"?>
                    <ui version="4.0">
                    <class>djdialog1</class>
                    <widget class="QDialog" name="djdialog1">
                    <property name="windowModality">
                    <enum>Qt::ApplicationModal</enum>
                    </property>
                    <property name="geometry">
                    <rect>
                    <x>0</x>
                    <y>0</y>
                    <width>334</width>
                    <height>300</height>
                    </rect>
                    </property>
                    <property name="windowTitle">
                    <string>DJs-Dialog</string>
                    </property>
                    <widget class="QTextEdit" name="int1box">
                    <property name="geometry">
                    <rect>
                    <x>73</x>
                    <y>10</y>
                    <width>61</width>
                    <height>41</height>
                    </rect>
                    </property>
                    <property name="toolTip">
                    <string>int 1 here</string>
                    </property>
                    </widget>
                    <widget class="QTextEdit" name="int2box">
                    <property name="geometry">
                    <rect>
                    <x>73</x>
                    <y>70</y>
                    <width>61</width>
                    <height>41</height>
                    </rect>
                    </property>
                    </widget>
                    <widget class="QLabel" name="label">
                    <property name="geometry">
                    <rect>
                    <x>160</x>
                    <y>10</y>
                    <width>60</width>
                    <height>31</height>
                    </rect>
                    </property>
                    <property name="text">
                    <string>first int</string>
                    </property>
                    <property name="alignment">
                    <set>Qt::AlignCenter</set>
                    </property>
                    </widget>
                    <widget class="QLabel" name="label_2">
                    <property name="geometry">
                    <rect>
                    <x>160</x>
                    <y>70</y>
                    <width>91</width>
                    <height>21</height>
                    </rect>
                    </property>
                    <property name="text">
                    <string>second int</string>
                    </property>
                    <property name="alignment">
                    <set>Qt::AlignCenter</set>
                    </property>
                    </widget>
                    <widget class="QTextEdit" name="answerbox">
                    <property name="geometry">
                    <rect>
                    <x>70</x>
                    <y>150</y>
                    <width>104</width>
                    <height>41</height>
                    </rect>
                    </property>
                    </widget>
                    <widget class="QLabel" name="label_3">
                    <property name="geometry">
                    <rect>
                    <x>0</x>
                    <y>80</y>
                    <width>60</width>
                    <height>31</height>
                    </rect>
                    </property>
                    <property name="styleSheet">
                    <string notr="true">color: rgb(0, 0, 255);
                    font: 16pt "Bitstream Charter";</string>
                    </property>
                    <property name="text">
                    <string>+</string>
                    </property>
                    <property name="alignment">
                    <set>Qt::AlignCenter</set>
                    </property>
                    </widget>
                    <widget class="QPushButton" name="GoButton">
                    <property name="geometry">
                    <rect>
                    <x>90</x>
                    <y>230</y>
                    <width>87</width>
                    <height>27</height>
                    </rect>
                    </property>
                    <property name="text">
                    <string>Compute</string>
                    </property>
                    </widget>
                    <widget class="QPushButton" name="clearbutton">
                    <property name="geometry">
                    <rect>
                    <x>200</x>
                    <y>230</y>
                    <width>87</width>
                    <height>27</height>
                    </rect>
                    </property>
                    <property name="text">
                    <string>Clear data</string>
                    </property>
                    </widget>
                    </widget>
                    <resources/>
                    <connections/>
                    </ui>

                    Your ui file is ok too

                    I think i found the problem, maybe you don't have an instance of djdialog on your main?

                    What do you have on your main.cpp file ?

                    replace your main.cpp with the following code and everything will be ok (i hope)

                    #include <QApplication>
                    
                    #include "djdialog1.h"
                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                        djdialog1 w;// create an instance of your form 
                        w.show();// show your form 
                    
                        return a.exec();
                    }
                    

                    Keep me informed !

                    D 1 Reply Last reply
                    0
                    • M mostefa

                      @DocDJ said in How can I send output to a widget:

                      @mostefa Here is my .ui file:
                      <?xml version="1.0" encoding="UTF-8"?>
                      <ui version="4.0">
                      <class>djdialog1</class>
                      <widget class="QDialog" name="djdialog1">
                      <property name="windowModality">
                      <enum>Qt::ApplicationModal</enum>
                      </property>
                      <property name="geometry">
                      <rect>
                      <x>0</x>
                      <y>0</y>
                      <width>334</width>
                      <height>300</height>
                      </rect>
                      </property>
                      <property name="windowTitle">
                      <string>DJs-Dialog</string>
                      </property>
                      <widget class="QTextEdit" name="int1box">
                      <property name="geometry">
                      <rect>
                      <x>73</x>
                      <y>10</y>
                      <width>61</width>
                      <height>41</height>
                      </rect>
                      </property>
                      <property name="toolTip">
                      <string>int 1 here</string>
                      </property>
                      </widget>
                      <widget class="QTextEdit" name="int2box">
                      <property name="geometry">
                      <rect>
                      <x>73</x>
                      <y>70</y>
                      <width>61</width>
                      <height>41</height>
                      </rect>
                      </property>
                      </widget>
                      <widget class="QLabel" name="label">
                      <property name="geometry">
                      <rect>
                      <x>160</x>
                      <y>10</y>
                      <width>60</width>
                      <height>31</height>
                      </rect>
                      </property>
                      <property name="text">
                      <string>first int</string>
                      </property>
                      <property name="alignment">
                      <set>Qt::AlignCenter</set>
                      </property>
                      </widget>
                      <widget class="QLabel" name="label_2">
                      <property name="geometry">
                      <rect>
                      <x>160</x>
                      <y>70</y>
                      <width>91</width>
                      <height>21</height>
                      </rect>
                      </property>
                      <property name="text">
                      <string>second int</string>
                      </property>
                      <property name="alignment">
                      <set>Qt::AlignCenter</set>
                      </property>
                      </widget>
                      <widget class="QTextEdit" name="answerbox">
                      <property name="geometry">
                      <rect>
                      <x>70</x>
                      <y>150</y>
                      <width>104</width>
                      <height>41</height>
                      </rect>
                      </property>
                      </widget>
                      <widget class="QLabel" name="label_3">
                      <property name="geometry">
                      <rect>
                      <x>0</x>
                      <y>80</y>
                      <width>60</width>
                      <height>31</height>
                      </rect>
                      </property>
                      <property name="styleSheet">
                      <string notr="true">color: rgb(0, 0, 255);
                      font: 16pt "Bitstream Charter";</string>
                      </property>
                      <property name="text">
                      <string>+</string>
                      </property>
                      <property name="alignment">
                      <set>Qt::AlignCenter</set>
                      </property>
                      </widget>
                      <widget class="QPushButton" name="GoButton">
                      <property name="geometry">
                      <rect>
                      <x>90</x>
                      <y>230</y>
                      <width>87</width>
                      <height>27</height>
                      </rect>
                      </property>
                      <property name="text">
                      <string>Compute</string>
                      </property>
                      </widget>
                      <widget class="QPushButton" name="clearbutton">
                      <property name="geometry">
                      <rect>
                      <x>200</x>
                      <y>230</y>
                      <width>87</width>
                      <height>27</height>
                      </rect>
                      </property>
                      <property name="text">
                      <string>Clear data</string>
                      </property>
                      </widget>
                      </widget>
                      <resources/>
                      <connections/>
                      </ui>

                      Your ui file is ok too

                      I think i found the problem, maybe you don't have an instance of djdialog on your main?

                      What do you have on your main.cpp file ?

                      replace your main.cpp with the following code and everything will be ok (i hope)

                      #include <QApplication>
                      
                      #include "djdialog1.h"
                      int main(int argc, char *argv[])
                      {
                          QApplication a(argc, argv);
                          djdialog1 w;// create an instance of your form 
                          w.show();// show your form 
                      
                          return a.exec();
                      }
                      

                      Keep me informed !

                      D Offline
                      D Offline
                      DocDJ
                      wrote on last edited by
                      #22

                      @mostefa THANK YOU, THANK YOU!!! That did it. I will analyze it to understand what I did wrong.

                      M 1 Reply Last reply
                      0
                      • D DocDJ

                        @mostefa THANK YOU, THANK YOU!!! That did it. I will analyze it to understand what I did wrong.

                        M Offline
                        M Offline
                        mostefa
                        wrote on last edited by mostefa
                        #23

                        @DocDJ said in How can I send output to a widget:

                        @mostefa THANK YOU, THANK YOU!!! That did it. I will analyze it to understand what I did wrong.

                        So the problem is solved now?

                        Good !

                        I advice you to read more about qt , if you want to go further

                        http://doc.qt.io/qt-5/gettingstarted.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