PDA

View Full Version : copy string from text box



Rekha
26th July 2006, 10:53
how to copy a string from one text box to another textbox?
there are 2 text boxes, text1 and text2 and an enter button.. on pressing enter button contents from text1 widget should get transferred to text2..
only the function to copy from text1 to text2 is required..
Pls check the following code is correct

void update()
{
QString str;
str=text1->toPlainText();
text2->setText(str);
}

jpn
26th July 2006, 11:02
What did you try so far? And what is a "text box"? QLineEdit? QTextEdit? QTextBrowser? ...



// line edit
lineEdit2->setText(lineEdit1->text());

// text edit
textEdit2->setPlainText(textEdit1->toPlainText());


PS. QLineEdit offers a signal returnPressed().

Rekha
26th July 2006, 11:07
textbox meansTextEdit.. don know why my code is not working



#ifndef TEXT_H
#define TEXT_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QPushButton>
#include <QtGui/QTextEdit>
#include <QtGui/Qobject>

class Ui_Dialog:public QObject
{
Q_Object
public:
QPushButton *exit;
QTextEdit *text2;
QPushButton *enter;
QTextEdit *text1;

void setupUi(QDialog *Dialog)
{
Dialog->setObjectName(QString::fromUtf8("Dialog"));
Dialog->resize(QSize(550, 458).expandedTo(Dialog->minimumSizeHint()));
exit = new QPushButton(Dialog);
exit->setObjectName(QString::fromUtf8("exit"));
exit->setGeometry(QRect(190, 340, 131, 36));
text2 = new QTextEdit(Dialog);
text2->setObjectName(QString::fromUtf8("text2"));
text2->setGeometry(QRect(380, 50, 104, 64));
enter = new QPushButton(Dialog);
enter->setObjectName(QString::fromUtf8("enter"));
enter->setGeometry(QRect(220, 70, 111, 36));
text1 = new QTextEdit(Dialog);
text1->setObjectName(QString::fromUtf8("text1"));
text1->setGeometry(QRect(70, 50, 104, 64));
retranslateUi(Dialog);
QObject::connect(enter, SIGNAL(clicked()),Dialog, SLOT(update()));
QObject::connect(exit, SIGNAL(clicked()), Dialog, SLOT(reject()));

QMetaObject::connectSlotsByName(Dialog);
} // setupUi

void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
exit->setText(QApplication::translate("Dialog", "Exit", 0, QApplication::UnicodeUTF8));
enter->setText(QApplication::translate("Dialog", "enter", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Dialog);
} // retranslateUi
void update()
{
text2->setPlainText(text1->toPlainText());
}


};

namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui

#endif // TEXT_H

pls help me out

jpn
26th July 2006, 11:29
You have just added a function update(), it's not declared as a slot. And why on the earth do you modify a file automatically generated by UIC? Next time you run UIC your modifies get overwritten.

See designer docs for Using a Component in Your Application (http://doc.trolltech.com/4.1/designer-using-a-component.html).

Rekha
27th July 2006, 07:29
hi,
I have attached my textr.cpp,textr.h,main.cpp files..the function to copy from one textedit to another textedit widget is not working.. please check whats wrong in my coding.. dont now why its not working.. i have tried a lot:(

jpn
27th July 2006, 08:11
hi,
I have attached my textr.cpp,textr.h,main.cpp files..the function to copy from one textedit to another textedit widget is not working.. please check whats wrong in my coding.. dont now why its not working.. i have tried a lot:(
You did not read the link (http://doc.trolltech.com/4.1/designer-using-a-component.html), did you?

Don't modify the source code generated by the UIC (UI Compiler). Just include the .ui file in your project and go read this link (http://doc.trolltech.com/4.1/designer-using-a-component.html) again to see how to use it properly in your project. Pay special attention to sections "The Single Inheritance Approach" and "The Multiple Inheritance Approach" and choose one of them.

I have attached a small example illustrating how to do what I believe you want to do. The example uses the single inheritance approach.

marvaneke
27th July 2006, 19:21
Hi,

On the page :
http://doc.trolltech.com/4.1/designer-using-a-component.html
I have tried the :
The Multiple Inheritance Approach
with the :
A Dialog With Auto-Connect

The code is ( too ;-) ) simple.

Regards.