Results 1 to 5 of 5

Thread: EDITED: Representing an Array REDUX!!!!

  1. #1
    Join Date
    Nov 2009
    Location
    Southern California
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question EDITED: Representing an Array REDUX!!!!

    Hello,
    I've got the official book: http://qt.nokia.com/developer/books/...-4-2nd-edition, but I've come to part where I'm not sure which way to go.

    I've got an array of 100 integers that are 3 integers long. I've setup my inputmasks on my lineEdits to be able to control this, so data sanitation is already handled. I'm trying to figure out the best way to both display this data, as well as edit it.

    • Is it possible to create pointers of lineEdits, put them in a QList container, and display them as well as access them through for() loops?
    • Is it possible to create an array within another class, and simply have 100 line edits point to said array. lineEdit00 points to numbers[0]?
    • Am I missing something?


    Any help would be great. Thanks for such a nice forum to ask questions.
    -bobby

    Qt Code:
    1. for(int i = 0; i < 100; i++)
    2. {
    3. // Setup the proper label
    4. if( i < 10)
    5. {
    6. labelPtr = new QLabel(tr("0%1").arg(i));
    7. }else{
    8. labelPtr = new QLabel(tr("%1").arg(i));
    9. }
    10.  
    11. // Now the Address Cell
    12. lePtr = new QLineEdit();
    13. lePtr->setInputMask("999");
    14. // if it's cell 00 make uneditable
    15. if(i < 1)
    16. {
    17. lePtr->setText("001");
    18. lePtr->setReadOnly(true);
    19. }
    20. memAddr.append(lePtr);
    21.  
    22. }
    23.  
    24. // Fill in the layout and display it
    25. for( int i = 0; i < 100; i++)
    26. {
    27. layout->addWidget(memAddr.at(i));
    28. }
    29.  
    30. window->setLayout(layout);
    31. window->show();
    To copy to clipboard, switch view to plain text mode 
    EDIT:
    Ok so I put my line edits into a QList, and I'm going to call them. my idea is that I have to use a forloop similar to the one I did, but with the addition to the labels as well.
    I really need to know how to take something like this that I pulled off, and put it into my application. Do I stick everything into the mainWindow.cpp (implementation) or do I make a new class, I really don't know.

    Another thought is to promote a groupbox into a "myGroupBox" and have the code run in there, but I'm really not clear how to do that, even with the help of Google.

    -Bobby
    Last edited by bobby; 16th November 2009 at 00:46. Reason: Additional Information

  2. #2
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Representing an Array

    Take a look at QTableView and QTableWidget classes, maybe this is what you need(?)
    Last edited by calhal; 15th November 2009 at 23:04. Reason: updated contents
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: EDITED: Representing an Array REDUX!!!!

    I suggest you take a look at the answer you have already been given.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Nov 2009
    Location
    Southern California
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: EDITED: Representing an Array REDUX!!!!

    Thanks guys!
    I ended up putting the lineEdits into a QList of lineEdit pointers and then I added them into a grid layout row by row.

    It may not be the best way, but it definitely worked. I think I would have been better off customizing a widget for my use, but I simply don't know how, so a QGridLayout of labels and lineEdits worked.

    Thanks again!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: EDITED: Representing an Array REDUX!!!!

    Did you try QTableWidget?

    Qt Code:
    1. QTableWidget *table = new QTableWidget(100,100);
    2. for(int r = 0; r < 100; ++r)
    3. for(int c = 0; c < 100; ++c)
    4. table->item(r,c)->setText(QString::number(qrand()%1000));
    5. table->show();
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Accessing array in both C++ and QtScript
    By abernat in forum Qt Programming
    Replies: 10
    Last Post: 6th September 2009, 22:21
  2. Problems passing an array of pointers to objects to a function
    By Valheru in forum General Programming
    Replies: 16
    Last Post: 30th June 2008, 00:11
  3. Problem in converting QString to QChar array?
    By KaKa in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2007, 00:38
  4. How to create QPixmap from unsigned character array?
    By rashidbutt in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 18:25
  5. QSettings again ... how to remove array elements
    By Mike in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 08:58

Tags for this Thread

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.