Results 1 to 15 of 15

Thread: QTableWidget

  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTableWidget

    Hello anyone,

    I ám using fc6 with Qt-4.2
    I have a Dialog with a freesTable widget with 1 collum.
    I can add a row through a another Dialog into freesTable no problem.
    I want to hold the row in a QList<> and when i startup the application it will iterate first
    through the QList and place the row in my freesTable.
    But there is nothing showing up in freesTable.
    Can anybody help me with this problem.

    The header file frees.h
    Qt Code:
    1. #include <QtGui>
    2. #include "ui_freesdialog.h"
    3.  
    4. class freesDialog : public QDialog, public Ui::freesDialog
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. freesDialog(QList<QString> *list, QWidget *parent=0);
    10.  
    11. public slots:
    12. void add();
    13.  
    14. private slots:
    15. void done(int result);
    16.  
    17. private:
    18. QList<QString> list;
    19.  
    20. };
    To copy to clipboard, switch view to plain text mode 

    The implentation file frees.cpp
    Qt Code:
    1. #include <QtCore>
    2.  
    3. #include "frees.h"
    4. #include "frezen.h"
    5.  
    6. freesDialog::freesDialog(QList<QString> *list, QWidget *parent)
    7. :QDialog(parent)
    8.  
    9. {
    10. setupUi(this);
    11.  
    12. for(int row = 0; row < list->count(); ++row) {
    13. QString frees = list->at(row);
    14. freesTable->setItem(row, 0, new QTableWidgetItem(frees)); //Something is wrong here.
    15. }
    16. connect(pbAdd, SIGNAL(clicked()), this, SLOT(add()));
    17. connect(pbRemove, SIGNAL(clicked()), this, SLOT(remove()));
    18. }
    19.  
    20.  
    21. void freesDialog::add()
    22.  
    23. {
    24. frezenDialog dlg(this);
    25. if( dlg.exec() == QDialog::Accepted ) {
    26.  
    27. QString materiaal = dlg.matComboBox->currentText();
    28. int row = freesTable->rowCount();
    29. freesTable->insertRow(row);
    30. freesTable->setItem(row, 0, new QTableWidgetItem(materiaal));
    31. }
    32. }
    33.  
    34.  
    35. void freesDialog::done(int result)
    36. {
    37.  
    38. if(result == QDialog::Accepted) {
    39. for(int row = 0; row < freesTable->rowCount(); ++row) {
    40. QString materiaal = freesTable->item(row, 0)->text();
    41. list.append(QString(materiaal)); // Give a error Undefined reference to Frezen::Frezen(QString const&)
    42. }
    43. }
    44. QDialog::done(result);
    45. }
    To copy to clipboard, switch view to plain text mode 

    The main file main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "frees.h"
    3.  
    4. int main(int argc, char *argv[])
    5.  
    6. {
    7. QApplication app(argc, argv);
    8. QList<Frezen> list;
    9. freesDialog freesdlg(&list);
    10. return freesdlg.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableWidget

    Maybe you forgot to set the column count? See QTableWidget::setColumnCount() or do it via designer.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget

    Actually its more likely you forgot setRowCount()...

  4. #4
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget

    I have set the collumcount in QT Designer i think tht is not the problem.
    I think the problem sits in the frees.cpp in the line's.

    #
    for(int row = 0; row < list->count(); ++row) {
    #
    QString frees = list->at(row);
    #
    freesTable->setItem(row, 0, new QTableWidgetItem(frees)); //Something is wrong here.
    #
    }

    and in the line's
    #
    for(int row = 0; row < freesTable->rowCount(); ++row) {
    #
    QString materiaal = freesTable->item(row, 0)->text();
    #
    list.append(QString(materiaal)); // Give a error Undefined reference to Frezen::Frezen(QString const&)

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget

    Where do you populate the list you pass in main.cpp to the dialog? Ibelieve there is no problem, its just the list... It is empty...

  6. #6
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget

    I populate the list in frees.cpp
    Qt Code:
    1. void freesDialog::done(int result)
    2. {
    3.  
    4. if(result == QDialog::Accepted) {
    5. for(int row = 0; row < freesTable->rowCount(); ++row) {
    6. QString materiaal = freesTable->item(row, 0)->text();
    7. list.append(QString(materiaal)); // Give a error Undefined reference to Frezen::Frezen(QString const&)
    8. }
    9. }
    10. QDialog::done(result);
    11. }
    To copy to clipboard, switch view to plain text mode 

    When compiling he give's a error on line
    list.append(QString(materiaal));
    I think there some wrong in the code on this line.

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget

    I don't understand something: in main.cpp you create the dialog by passing a QList to it.
    In the constructor of the dialog you fill a table from this list ( WHICH IS EMPTY AT THE MOMENT !!! ). What do you expect to see? Or, is this the correct code? Maybe I'm missing something.

  8. #8
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget

    Maybe i must change the main.cpp because the code is not right.
    Qt Code:
    1. #include <QApplication>
    2. #include "frees.h"
    3.  
    4. int main(int argc, char *argv[])
    5.  
    6. {
    7. QApplication app(argc, argv);
    8. QList<Frezen> list;
    9. freesDialog freesdlg(&list);
    10. return freesdlg.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    I will delete the line
    QList<Frezen> list;
    Mabye that will solve the problem.

  9. #9
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget

    I have delete the line QLIst<Frezen> list.
    Qt Code:
    1. #include <QApplication>
    2. #include "frees.h"
    3.  
    4. int main(int argc, char *argv[])
    5.  
    6. {
    7. QApplication app(argc, argv);
    8. freesDialog freesdlg;
    9. return freesdlg.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    When i compile the application it give's a error.
    main.cpp error: no matching function for call to freesDialog::freesDialog().

  10. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget

    because freesDialog does not have a default constructor ( a constructor with no parameters ).

    From what I've seen the constructor of freesDialog has two parameters: a QList and a QWidget.

    You should modify the constructor or create it accordingly in main.cpp.

    Regards.

  11. #11
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget

    Can you give me a example over modify the constructor

  12. #12
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget

    Sure...

    In the header:
    Qt Code:
    1. public:
    2. freesDialog( QWidget* parent = NULL );
    3. ...
    To copy to clipboard, switch view to plain text mode 

    In the cpp:
    Qt Code:
    1. freesDialog::freesDialog( QWidget* parent )
    2. :QDialog( parent )
    3. {
    4. ... do some stuff
    5. }
    To copy to clipboard, switch view to plain text mode 

    Now, when you create the dialog, you can call the constructor without any parameters.
    Also, there is no point in filling the table from that empty list in the constructor... So you can remove it...


    Regards

  13. #13
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget

    It is not working the Qlist stays empty i think.
    Nothing showing up in QTableWidget.
    I try to search for orther sollution.

    Thanks Marcel for your time and suggestions.

  14. #14
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget

    Definitely you're doing something wrong there... What is in the list and where the list gets populated? I mean, where do you put items in the list?

    Before filling the table from the list, there has to be actually something in the list in the first place....

    Regards.

  15. #15
    Join Date
    Jan 2006
    Posts
    115
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget

    I know something wrong there...

    I get my items from this with some comment on the line's maybe helps.

    Qt Code:
    1. void freesDialog::add()
    2.  
    3. {
    4. frezenDialog dlg(this); // When i clicked on de pushbutton it shows this inputdialog.
    5. if( dlg.exec() == QDialog::Accepted ) {
    6.  
    7. QString materiaal = dlg.matComboBox->currentText(); // the text i choose in my matComboBox
    8. int row = freesTable->rowCount();
    9. freesTable->insertRow(row);
    10. freesTable->setItem(row, 0, new QTableWidgetItem(materiaal)); //Put the text onto the QTableWidget.
    11.  
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    From another function
    void freesDialog::done(int result)
    Qt Code:
    1. QString materiaal = freesTable->item(row, 0)->text();
    2. list.append(materiaal); //materiaal must append to QList<Qstring> list
    To copy to clipboard, switch view to plain text mode 

    I think this the method to put something in list maby i wrong.

Similar Threads

  1. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 01:57
  2. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 19th December 2006, 23:27
  3. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 18:46
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21: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.