Results 1 to 18 of 18

Thread: QListWidget

  1. #1
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Post QListWidget

    I created QListWIdget in one class, wand to add item to that list widget from another class.

    class TestScriptGeneratorDialog - QListWidget *m_scriptWidget;

    Class PresskeyDialog -

    pTest = new TestScriptGeneratorDialog;
    pTest->m_scriptWidget->addItem("sdss");

    Add item is not working. HOw can we do it.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget

    What is not working ? What error are you getting ?

    Also, did you create object of QListWidget ? like m_scriptWidget = new QListWidget... ??????

  3. #3
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: QListWidget

    Yes i created object of QListwidget.

    I am not getting any error. But itm is not adding to QListWidget.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidget

    Please send more code. Best would be a minimal compilable example reproducing your problem.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget

    do you see the listwidget ?
    also try calling listWidget->update() after calling addItem, and check if it works..

  6. #6
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    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();
    }

  7. #7
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    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();
    }

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidget

    and how does your header look like? is m_scriptWidget public? And please use the code tags.

  9. #9
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    {
    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;
    };

  10. #10
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget

    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

  11. #11
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    Quote Originally Posted by aamer4yu View Post
    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
    I am using another QDialog because, except OK, Cancel i have QCheckbox, QLineedit to add in that dialog.

  12. #12
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidget

    Quote Originally Posted by bismitapadhy View Post
    void PressKeyDialog:nOk(void)
    {
    pTest = new TestScriptGeneratorDialog;
    pTest->m_scriptWidget->addItem("sdss");
    pTest->m_scriptWidget->update();
    accept();
    }
    Ehm, where did you show pTest?

  13. #13
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    TestScriptGeneratorDialog * pTest;

    PTest i have taken as a pointer of this class. What to show.

  14. #14
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidget

    Quote Originally Posted by bismitapadhy View Post
    What to show.
    Your dialog? pTest->exec();

  15. The following user says thank you to Lykurg for this useful post:

    bismitapadhy (18th March 2010)

  16. #15
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    Quote Originally Posted by Lykurg View Post
    Your dialog? pTest->exec();
    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?
    Attached Images Attached Images

  17. #16
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    Quote Originally Posted by Lykurg View Post
    Your dialog? pTest->exec();
    Did you have any solution for this

  18. #17
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget

    Quote Originally Posted by bismitapadhy View Post
    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.
    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...
    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 pass the pointer to your QListWidget to this dialog.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  19. #18
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget

    Quote Originally Posted by faldżip View Post
    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.
    I already searched and didn't found the solution.

Similar Threads

  1. QListWidget with STL
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2007, 16:16
  2. QTableWidget or QListWidget
    By bpetty in forum Newbie
    Replies: 3
    Last Post: 6th December 2006, 19:40
  3. QListWidget help please
    By munna in forum Qt Programming
    Replies: 5
    Last Post: 28th November 2006, 12:16
  4. Another QListWidget bug?
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2006, 13:40
  5. Possible bug of Qt on QListWidget?
    By SkripT in forum Qt Programming
    Replies: 9
    Last Post: 28th March 2006, 13:05

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.