Results 1 to 7 of 7

Thread: copy string from text box

  1. #1
    Join Date
    Jul 2006
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default copy string from text box

    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
    Qt Code:
    1. void update()
    2. {
    3. QString str;
    4. str=text1->toPlainText();
    5. text2->setText(str);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 26th July 2006 at 12:42. Reason: changed [ quote ] to [ code ]

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: copy string from text box

    What did you try so far? And what is a "text box"? QLineEdit? QTextEdit? QTextBrowser? ...

    Qt Code:
    1. // line edit
    2. lineEdit2->setText(lineEdit1->text());
    3.  
    4. // text edit
    5. textEdit2->setPlainText(textEdit1->toPlainText());
    To copy to clipboard, switch view to plain text mode 

    PS. QLineEdit offers a signal returnPressed().
    J-P Nurmi

  3. #3
    Join Date
    Jul 2006
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: copy string from text box

    textbox meansTextEdit.. don know why my code is not working

    Qt Code:
    1. #ifndef TEXT_H
    2. #define TEXT_H
    3.  
    4. #include <QtCore/QVariant>
    5. #include <QtGui/QAction>
    6. #include <QtGui/QApplication>
    7. #include <QtGui/QButtonGroup>
    8. #include <QtGui/QDialog>
    9. #include <QtGui/QPushButton>
    10. #include <QtGui/QTextEdit>
    11. #include <QtGui/Qobject>
    12.  
    13. class Ui_Dialog:public QObject
    14. {
    15. Q_Object
    16. public:
    17. QPushButton *exit;
    18. QTextEdit *text2;
    19. QPushButton *enter;
    20. QTextEdit *text1;
    21.  
    22. void setupUi(QDialog *Dialog)
    23. {
    24. Dialog->setObjectName(QString::fromUtf8("Dialog"));
    25. Dialog->resize(QSize(550, 458).expandedTo(Dialog->minimumSizeHint()));
    26. exit = new QPushButton(Dialog);
    27. exit->setObjectName(QString::fromUtf8("exit"));
    28. exit->setGeometry(QRect(190, 340, 131, 36));
    29. text2 = new QTextEdit(Dialog);
    30. text2->setObjectName(QString::fromUtf8("text2"));
    31. text2->setGeometry(QRect(380, 50, 104, 64));
    32. enter = new QPushButton(Dialog);
    33. enter->setObjectName(QString::fromUtf8("enter"));
    34. enter->setGeometry(QRect(220, 70, 111, 36));
    35. text1 = new QTextEdit(Dialog);
    36. text1->setObjectName(QString::fromUtf8("text1"));
    37. text1->setGeometry(QRect(70, 50, 104, 64));
    38. retranslateUi(Dialog);
    39. QObject::connect(enter, SIGNAL(clicked()),Dialog, SLOT(update()));
    40. QObject::connect(exit, SIGNAL(clicked()), Dialog, SLOT(reject()));
    41.  
    42. QMetaObject::connectSlotsByName(Dialog);
    43. } // setupUi
    44.  
    45. void retranslateUi(QDialog *Dialog)
    46. {
    47. Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
    48. exit->setText(QApplication::translate("Dialog", "Exit", 0, QApplication::UnicodeUTF8));
    49. enter->setText(QApplication::translate("Dialog", "enter", 0, QApplication::UnicodeUTF8));
    50. Q_UNUSED(Dialog);
    51. } // retranslateUi
    52. void update()
    53. {
    54. text2->setPlainText(text1->toPlainText());
    55. }
    56.  
    57.  
    58. };
    59.  
    60. namespace Ui {
    61. class Dialog: public Ui_Dialog {};
    62. } // namespace Ui
    63.  
    64. #endif // TEXT_H
    To copy to clipboard, switch view to plain text mode 
    pls help me out
    Last edited by jacek; 26th July 2006 at 12:42. Reason: changed [ quote ] to [ code ]

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: copy string from text box

    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.
    J-P Nurmi

  5. #5
    Join Date
    Jul 2006
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default copy string from text box

    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
    Attached Files Attached Files

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: copy string from text box

    Quote Originally Posted by Rekha
    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, 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 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.
    Attached Files Attached Files
    J-P Nurmi

  7. The following 2 users say thank you to jpn for this useful post:

    fnmblot (10th August 2006), Rekha (27th July 2006)

  8. #7
    Join Date
    Jun 2006
    Posts
    18
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool Re: copy string from text box

    Hi,

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

    The code is ( too ;-) ) simple.

    Regards.

  9. The following user says thank you to marvaneke for this useful post:

    Rekha (2nd August 2006)

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02
  3. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  4. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.