Results 1 to 19 of 19

Thread: Text box and list box connectivity

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

    Post Text box and list box connectivity

    hi,
    i'm beginner to Qt.. there is a text box and list box,when u enter some characters in the text box and give enter to a push button,it should add all the characters to listbox.. so i had written code 4 tat,everything works fine,but adding characters to listbox is not wrkg fine.. the code for adding characters is given below,
    pls check wats wrong with code
    Qt Code:
    1. void show()
    2. {
    3. QTextStream str,str2;
    4. str=text1.text();
    5. str1=length(str);
    6.  
    7. for(int i=0;i<str1;i++)
    8. {
    9.  
    10. str2=insertText(list1.at(i));
    11. i++;
    12. }
    13. display->setText(display->text()+str2);
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 25th July 2006 at 09:38. Reason: Added [code] tags

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    Please use the code tag to insert your code.

    Quote Originally Posted by Rekha
    there is a text box and list box,when u enter some characters in the text box and give enter to a push button,it should add all the characters to listbox..
    How should the characters be added to the list box ? Should each character become an item in the listbox or each word becomes an item or each line should be an item in the list box ?

    Qt Code:
    1. void show()
    2. {
    3. QTextStream str,str2;
    4. str=text1.text();
    5. str1=length(str);
    6.  
    7. for(int i=0;i<str1;i++)
    8. {
    9.  
    10. str2=insertText(list1.at(i));
    11. i++;
    12. }
    13. display->setText(display->text()+str2);
    14. }
    To copy to clipboard, switch view to plain text mode 

    What is list1 and display ?

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

    Default Re: Text box and list box connectivity

    oh sorry,
    text1 is the name of text box widget
    list1 is the name of the listWidget name
    display is the function used to display

    the complete text thats there in text box text1 should come to the list box, it can come as a block or else word by word or character by character

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    try this

    Qt Code:
    1. void show()
    2. {
    3. list1.addItem(text1.toPlainText());
    4. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Text box and list box connectivity

    no its not wkg..
    i will add code what i had written again 4m starting
    /////////////////code/////////////////

    Qt Code:
    1. class Ui_Dialog
    2. {
    3. public:
    4. QWidget *layoutWidget;
    5. QHBoxLayout *hboxLayout;
    6. QPushButton *exit;
    7. QTextEdit *text2;
    8. QListWidget *list1;
    9. QTextEdit *text1;
    10. QPushButton *enter;
    11.  
    12. void setupUi(QDialog *Dialog)
    13. {
    14. Dialog->setObjectName(QString::fromUtf8("Dialog"));
    15. Dialog->resize(QSize(552, 555).expandedTo(Dialog->minimumSizeHint()));
    16. layoutWidget = new QWidget(Dialog);
    17. layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
    18. layoutWidget->setGeometry(QRect(20, 430, 351, 38));
    19. hboxLayout = new QHBoxLayout(layoutWidget);
    20. hboxLayout->setSpacing(6);
    21. hboxLayout->setMargin(0);
    22. hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
    23. exit = new QPushButton(layoutWidget);
    24. exit->setObjectName(QString::fromUtf8("exit"));
    25.  
    26. hboxLayout->addWidget(exit);
    27.  
    28. text2 = new QTextEdit(Dialog);
    29. text2->setObjectName(QString::fromUtf8("text2"));
    30. text2->setGeometry(QRect(60, 220, 104, 52));
    31. list1 = new QListWidget(Dialog);
    32. list1->setObjectName(QString::fromUtf8("list1"));
    33. list1->setGeometry(QRect(380, 90, 120, 80));
    34. text1 = new QTextEdit(Dialog);
    35. text1->setObjectName(QString::fromUtf8("text1"));
    36. text1->setGeometry(QRect(60, 80, 104, 52));
    37. enter = new QPushButton(Dialog);
    38. enter->setObjectName(QString::fromUtf8("enter"));
    39. enter->setGeometry(QRect(210, 90, 108, 36));
    40. QWidget::setTabOrder(text1, enter);
    41. QWidget::setTabOrder(enter, list1);
    42. QWidget::setTabOrder(list1, text2);
    43. QWidget::setTabOrder(text2, exit);
    44. retranslateUi(Dialog);
    45. QObject::connect(exit, SIGNAL(clicked()), Dialog, SLOT(reject()));
    46. QObject::connect(enter, SIGNAL(clicked()), list1, SLOT(show()));
    47. QObject::connect(list1, SIGNAL(itemDoubleClicked(QListWidgetItem*)), text2, SLOT(copy()));
    48.  
    49. QMetaObject::connectSlotsByName(Dialog);
    50. } // setupUi
    51.  
    52. void retranslateUi(QDialog *Dialog)
    53. {
    54. Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
    55. exit->setText(QApplication::translate("Dialog", "Exit", 0, QApplication::UnicodeUTF8));
    56. enter->setText(QApplication::translate("Dialog", "Enter", 0, QApplication::UnicodeUTF8));
    57. Q_UNUSED(Dialog);
    58. } // retranslateUi
    59.  
    60. void show()
    61. {
    62. QTextStream str,str2;
    63. str=text1.text();
    64. str1=length(str);
    65. list1.addItem(text1.toPlainText());
    66. for(int i=0;i<str1;i++)
    67. {
    68.  
    69. str2=insertText(list1.at(i));
    70.  
    71. i++;
    72. }
    73. display->setText(display->text()+str2);
    74. }
    75.  
    76.  
    77. };
    To copy to clipboard, switch view to plain text mode 


    The problem is in void show() ;
    Last edited by wysota; 25th July 2006 at 09:28. Reason: Added [code] tags

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    change

    QObject::connect(enter, SIGNAL(clicked()), list1, SLOT(show()));

    to

    QObject::connect(enter, SIGNAL(clicked()), Dialog, SLOT(show()));

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

    Default Re: Text box and list box connectivity

    its not working

  8. #8
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    QObject::connect(enter, SIGNAL(clicked()), Dialog, SLOT(show()));

    sender - enter
    signal - clicked()
    receiver - Dialog
    slot - show()

    receiver tells the program where the slot is. Therefore the slot show() should be in the class Dialog and not in the Ui_Dialog.

    Sorry, my mistake. I did not see the slot in that big code.

    Please insert you code between the code tag.

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

    Default Re: Text box and list box connectivity

    at the end of code i had used namespace so its" Dialog class" only..

  10. #10
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    In that case it should be

    QObject::connect(enter, SIGNAL(clicked()), this, SLOT(show()));

    and proabably u'll need to add "public slots:" before the slot show(), if you have not added.

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

    Default Re: Text box and list box connectivity

    sorry to say but even that dint work.. can u guess what might be the problem

  12. #12
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    Can you please zip your code and attach here ?

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    Ui_Dialog class doesn't inherit QObject, thus it can't have slots.

    It looks like you are trying to modify a file produced by uic. You should use the single- or multi-inheritance approach instead, to avoid problems when you will have to generate it again. See Qt Designer docs.

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

    Default Re: Text box and list box connectivity

    i have zipped the sample.h file as u had asked..i have attached sample.cpp also along with that
    Attached Files Attached Files

  15. #15
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    ok here it is

    Qt Code:
    1. class Ui_Dialog : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. QWidget *layoutWidget;
    7. QHBoxLayout *hboxLayout;
    8. QPushButton *exit;
    9. QTextEdit *text2;
    10. QListWidget *list1;
    11. QPushButton *enter;
    12. QTextEdit *text1;
    13.  
    14. void setupUi(QDialog *Dialog)
    15. {
    16. Dialog->setObjectName(QString::fromUtf8("Dialog"));
    17. Dialog->resize(QSize(552, 555).expandedTo(Dialog->minimumSizeHint()));
    18. layoutWidget = new QWidget(Dialog);
    19. layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
    20. layoutWidget->setGeometry(QRect(230, 410, 131, 38));
    21. hboxLayout = new QHBoxLayout(layoutWidget);
    22. hboxLayout->setSpacing(6);
    23. hboxLayout->setMargin(0);
    24. hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
    25. exit = new QPushButton(layoutWidget);
    26. exit->setObjectName(QString::fromUtf8("exit"));
    27.  
    28. hboxLayout->addWidget(exit);
    29.  
    30. text2 = new QTextEdit(Dialog);
    31. text2->setObjectName(QString::fromUtf8("text2"));
    32. text2->setGeometry(QRect(60, 220, 104, 52));
    33. list1 = new QListWidget(Dialog);
    34. list1->setObjectName(QString::fromUtf8("list1"));
    35. list1->setGeometry(QRect(380, 90, 120, 80));
    36. enter = new QPushButton(Dialog);
    37. enter->setObjectName(QString::fromUtf8("enter"));
    38. enter->setGeometry(QRect(210, 90, 108, 36));
    39. text1 = new QTextEdit(Dialog);
    40. text1->setObjectName(QString::fromUtf8("text1"));
    41. text1->setGeometry(QRect(60, 80, 104, 52));
    42. QWidget::setTabOrder(text1, enter);
    43. QWidget::setTabOrder(enter, list1);
    44. QWidget::setTabOrder(list1, text2);
    45. QWidget::setTabOrder(text2, exit);
    46. retranslateUi(Dialog);
    47. QObject::connect(exit, SIGNAL(clicked()), this, SLOT(reject()));
    48. QObject::connect(enter, SIGNAL(clicked()), this, SLOT(show()));
    49. QObject::connect(list1, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(copy()));
    50. QObject::connect(text1, SIGNAL(textChanged()), this, SLOT(update()));
    51.  
    52. QMetaObject::connectSlotsByName(Dialog);
    53. } // setupUi
    54.  
    55. void retranslateUi(QDialog *Dialog)
    56. {
    57. Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
    58. exit->setText(QApplication::translate("Dialog", "Exit", 0, QApplication::UnicodeUTF8));
    59. enter->setText(QApplication::translate("Dialog", "Enter", 0, QApplication::UnicodeUTF8));
    60. Q_UNUSED(Dialog);
    61. } // retranslateUi
    62.  
    63. public slots:
    64.  
    65. void show()
    66. {
    67. list1->addItem(text1->toPlainText());
    68. }
    69.  
    70.  
    71. };
    To copy to clipboard, switch view to plain text mode 

    But I would not suggest you to do this way. Please look into Qt examples as on how the classes are designed.

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

    Default Re: Text box and list box connectivity

    its not working .. please say me
    1)the code to copy all the characters from the text box to list box when a push button like enter is being clicked after entering all the characters in the text box....... is not working

  17. #17
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    I have tested this and it works perfectly for me. When I click on the enter button the text gets copied to the list1.

    Ofcourse u'll need to add

    #include<QObject> in the beginning

    and

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


    at the end

  18. The following user says thank you to munna for this useful post:

    :db:sStrong (25th July 2006)

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

    Default Text box and list box connectivity

    on executing "make" command i'm getting the follwoing errors..
    wat 2 do?

    MyDialog.cpp: In member function `void MyDialog::copy()':
    MyDialog.cpp:16: error: `addItem' undeclared (first use this function)
    MyDialog.cpp:16: error: (Each undeclared identifier is reported only once for
    each function it appears in.)
    make: *** [MyDialog.o] Error 1

  20. #19
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Text box and list box connectivity

    We can't solve problems by using the same kind of thinking we used when we created them

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.