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
Code:
void show()
{
str=text1.text();
str1=length(str);
for(int i=0;i<str1;i++)
{
str2=insertText(list1.at(i));
i++;
}
display->setText(display->text()+str2);
}
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 ?
Code:
void show()
{
str=text1.text();
str1=length(str);
for(int i=0;i<str1;i++)
{
str2=insertText(list1.at(i));
i++;
}
display->setText(display->text()+str2);
}
What is list1 and display ?
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
Re: Text box and list box connectivity
try this
Code:
void show()
{
list1.addItem(text1.toPlainText());
}
Re: Text box and list box connectivity
no its not wkg..
i will add code what i had written again 4m starting
/////////////////code/////////////////
Code:
class Ui_Dialog
{
public:
{
Dialog
->setObjectName
(QString::fromUtf8("Dialog"));
Dialog
->resize
(QSize(552,
555).
expandedTo(Dialog
->minimumSizeHint
()));
layoutWidget
= new QWidget(Dialog
);
layoutWidget
->setObjectName
(QString::fromUtf8("layoutWidget"));
layoutWidget
->setGeometry
(QRect(20,
430,
351,
38));
hboxLayout->setSpacing(6);
hboxLayout->setMargin(0);
hboxLayout
->setObjectName
(QString::fromUtf8("hboxLayout"));
exit
->setObjectName
(QString::fromUtf8("exit"));
hboxLayout->addWidget(exit);
text2
->setObjectName
(QString::fromUtf8("text2"));
text2
->setGeometry
(QRect(60,
220,
104,
52));
list1
->setObjectName
(QString::fromUtf8("list1"));
list1
->setGeometry
(QRect(380,
90,
120,
80));
text1
->setObjectName
(QString::fromUtf8("text1"));
text1
->setGeometry
(QRect(60,
80,
104,
52));
enter
->setObjectName
(QString::fromUtf8("enter"));
enter
->setGeometry
(QRect(210,
90,
108,
36));
QWidget::setTabOrder(text1, enter
);
QWidget::setTabOrder(enter, list1
);
QWidget::setTabOrder(list1, text2
);
retranslateUi(Dialog);
QObject::connect(exit,
SIGNAL(clicked
()), Dialog,
SLOT(reject
()));
QObject::connect(enter,
SIGNAL(clicked
()), list1,
SLOT(show
()));
} // setupUi
void retranslateUi
(QDialog *Dialog
) {
Q_UNUSED(Dialog);
} // retranslateUi
void show()
{
str=text1.text();
str1=length(str);
list1.addItem(text1.toPlainText());
for(int i=0;i<str1;i++)
{
str2=insertText(list1.at(i));
i++;
}
display->setText(display->text()+str2);
}
};
The problem is in void show() ;
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()));
Re: Text box and list box connectivity
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.
Re: Text box and list box connectivity
at the end of code i had used namespace so its" Dialog class" only..
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.
Re: Text box and list box connectivity
sorry to say but even that dint work.. can u guess what might be the problem:(
Re: Text box and list box connectivity
Can you please zip your code and attach here ?
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.
2 Attachment(s)
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
Re: Text box and list box connectivity
ok here it is
Code:
{
Q_OBJECT
public:
{
Dialog
->setObjectName
(QString::fromUtf8("Dialog"));
Dialog
->resize
(QSize(552,
555).
expandedTo(Dialog
->minimumSizeHint
()));
layoutWidget
= new QWidget(Dialog
);
layoutWidget
->setObjectName
(QString::fromUtf8("layoutWidget"));
layoutWidget
->setGeometry
(QRect(230,
410,
131,
38));
hboxLayout->setSpacing(6);
hboxLayout->setMargin(0);
hboxLayout
->setObjectName
(QString::fromUtf8("hboxLayout"));
exit
->setObjectName
(QString::fromUtf8("exit"));
hboxLayout->addWidget(exit);
text2
->setObjectName
(QString::fromUtf8("text2"));
text2
->setGeometry
(QRect(60,
220,
104,
52));
list1
->setObjectName
(QString::fromUtf8("list1"));
list1
->setGeometry
(QRect(380,
90,
120,
80));
enter
->setObjectName
(QString::fromUtf8("enter"));
enter
->setGeometry
(QRect(210,
90,
108,
36));
text1
->setObjectName
(QString::fromUtf8("text1"));
text1
->setGeometry
(QRect(60,
80,
104,
52));
QWidget::setTabOrder(text1, enter
);
QWidget::setTabOrder(enter, list1
);
QWidget::setTabOrder(list1, text2
);
retranslateUi(Dialog);
QObject::connect(exit,
SIGNAL(clicked
()),
this,
SLOT(reject
()));
QObject::connect(enter,
SIGNAL(clicked
()),
this,
SLOT(show
()));
QObject::connect(text1,
SIGNAL(textChanged
()),
this,
SLOT(update
()));
} // setupUi
void retranslateUi
(QDialog *Dialog
) {
Q_UNUSED(Dialog);
} // retranslateUi
public slots:
void show()
{
list1->addItem(text1->toPlainText());
}
};
But I would not suggest you to do this way. Please look into Qt examples as on how the classes are designed.
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:o
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
Text box and list box connectivity
on executing "make" command i'm getting the follwoing errors..
wat 2 do?
Quote:
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
Re: Text box and list box connectivity