Yes i created object of QListwidget.
I am not getting any error. But itm is not adding to QListWidget.
Yes i created object of QListwidget.
I am not getting any error. But itm is not adding to QListWidget.
Please send more code. Best would be a minimal compilable example reproducing your problem.
TestScriptGeneratorDialog::TestScriptGeneratorDial og(QWidget * parent): QDialog(parent)
{
createWindow();
}
void TestScriptGeneratorDialog::createWindow()
{
m_scriptWidget = new QListWidget;
m_scriptWidget->setMaximumWidth(140);
}
void TestScriptGeneratorDialog:nAdd()
{
QString keyToAdd = (m_commandWidget->currentItem())->text();
if(keyToAdd == "Presskey")
{
PressKeyDialog *pressKey = new PressKeyDialog(this);
if (pressKey)
{
pressKey->exec();
delete pressKey;
}
}
}
PressKeyDialog::PressKeyDialog(QWidget * parent): QDialog(parent)
{
QPushButton *okButton = new QPushButton(tr("Ok"));
QPushButton *closeButton = new QPushButton(tr("Cancel"));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
connect(okButton, SIGNAL(clicked()), this, SLOT(onOk()));
}
void PressKeyDialog:nOk(void)
{
pTest = new TestScriptGeneratorDialog;
pTest->m_scriptWidget->addItem("sdss");
pTest->m_scriptWidget->update();
accept();
}
and how does your header look like? is m_scriptWidget public? And please use the code tags.
{
Q_OBJECT
public:
TestScriptGeneratorDialog(QWidget * parent = 0);
QListWidget * m_commandWidget;
QListWidget * m_scriptWidget;
private slots:
void onAdd();
void onRemove();
void onFinish();
private:
void createWindow();
};
class PressKeyDialog : public QDialog
{
Q_OBJECT
public:
PressKeyDialog(QWidget *parent = 0);
private slots:
void onOk();
private:
QLineEdit * m_pPressTime;
TestScriptGeneratorDialog * pTest;
};
Did you try to debug the code ? What path does it follow when you click the Add button ?
Code seems ok, hard to trace from this code. As lykurg said, a minimal compilable example reproducing your problem would be fair
Also, instead of PressKeyDialog, you could have used QMessageBox::question
do you see the listwidget ?
also try calling listWidget->update() after calling addItem, and check if it works..
It is not working, I am sending you some more code.
TestScriptGeneratorDialog::TestScriptGeneratorDial og(QWidget * parent): QDialog(parent)
{
createWindow();
}
void TestScriptGeneratorDialog::createWindow()
{
m_scriptWidget = new QListWidget;
m_scriptWidget->setMaximumWidth(140);
}
void TestScriptGeneratorDialog:nAdd()
{
QString keyToAdd = (m_commandWidget->currentItem())->text();
if(keyToAdd == "Presskey")
{
PressKeyDialog *pressKey = new PressKeyDialog(this);
if (pressKey)
{
pressKey->exec();
delete pressKey;
}
}
}
PressKeyDialog::PressKeyDialog(QWidget * parent): QDialog(parent)
{
QPushButton *okButton = new QPushButton(tr("Ok"));
QPushButton *closeButton = new QPushButton(tr("Cancel"));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
connect(okButton, SIGNAL(clicked()), this, SLOT(onOk()));
}
void PressKeyDialog:nOk(void)
{
pTest = new TestScriptGeneratorDialog;
pTest->m_scriptWidget->addItem("sdss");
pTest->m_scriptWidget->update();
accept();
}
TestScriptGeneratorDialog * pTest;
PTest i have taken as a pointer of this class. What to show.
bismitapadhy (18th March 2010)
I attached one file.On selecting each item on the left side it will open a dialog and pressing Ok in that dialog some item will be added to the rightside listwidget.
Everytime if i will create a new instance of the QLIstwidget, adding itm and doing exec() it is adding in the beginning of the list.
To keep one instance of QListWidget for all the dialog i need to keep a global variable which is not a good programming style.
So please let me know any other solution is there for this?
Hmm... So every time you are adding item to different QListWidget? So after clicking OK (or what do you have there) 10times, you will have 10 QListWidgets? I don't think that this is what you really want...
So pass the pointer to your QListWidget to this dialog.To keep one instance of QListWidget for all the dialog i need to keep a global variable which is not a good programming style.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Bookmarks