Unsolved How can I send output to a widget
-
@mostefa Thanks for the lines to add. I do not have QtCreator, because a package for it is not available on the Linux platform I am using (ClefOS 6.6) on an older IBM z390 mainframe system that does not have the hardware support for the newer ClefOS system.
-
@DocDJ said in How can I send output to a widget:
@mostefa Thanks for the lines to add. I do not have QtCreator, because a package for it is not available on the Linux platform I am using (ClefOS 6.6) on an older IBM z390 mainframe system that does not have the hardware support for the newer ClefOS system.
Ok ,
So your app work for now?
-
@mostefa Still does not work. NO errors, but no results in answerbox.
-
@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!
-
@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.
-
@DocDJ Underscores doesn't matter.
You should really check whether all connect calls succeed.
Can you post your header and cpp file? -
@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?
-
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.
-
-
@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?
-
@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> -
@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 !
-
@mostefa THANK YOU, THANK YOU!!! That did it. I will analyze it to understand what I did wrong.
-
@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