Results 1 to 19 of 19

Thread: Text box and list box connectivity

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 ?

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
  •  
Qt is a trademark of The Qt Company.