Results 1 to 19 of 19

Thread: foreach or alike

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default foreach or alike

    Qt Code:
    1. iconmodel->setQuery("SELECT `PictureForButtonMode` FROM `dictionary` WHERE `PictureForButtonMode` LIKE '%.%'");
    2.  
    3. while(iconmodel->query().next())
    4. {
    5. QString buttonFV = iconmodel->query().value(0).toString(); // = String = image file name
    6.  
    7. foreach(...) // is this possible ?
    8. {
    9. // The code below works when not in this foreach statement
    10. QString bttnPath = QApplication::applicationDirPath();
    11. bttnPath = "/home/dev/ttm/directory/icon/" + buttonFV;
    12.  
    13. stylesheet += "QListView { show-decoration-selected: 0; border:transparent; color: white; background: transparent ; }";
    14. stylesheet += "QListView::text { padding-right: 300px; }";
    15. stylesheet += "QListView::item {image: url(" +bttnPath + "); width: 135px; height: 207px; }";
    16.  
    17. iListView->setStyleSheet(stylesheet);
    18. }
    To copy to clipboard, switch view to plain text mode 

    this code works without the foreach but im getting the first image for each item and its using the same image for all of them

    what im trying to do is for each string assign the string filename to the item.... still cant get it working properly ...

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: foreach or alike

    foreach works with containers what is your container that you want to iterate over?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: foreach or alike

    using QSQLQueryModel as my container

  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: foreach or alike

    you can't use QSQLQueryModel in a foreach loop. It also isn't necessary since the while loop is there already.

    Further, what do you try to achieve? You code looks "strange":
    Qt Code:
    1. iListView->setStyleSheet(stylesheet);
    To copy to clipboard, switch view to plain text mode 
    will be overwritten each loop, that only the last one will take effect.

  5. #5
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: foreach or alike

    im trying to change the item image for each query value returned

  6. #6
    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: foreach or alike

    How about subclassing the model and reimplementing data() to return the proper icon for Qt::DecorationRole of each respective index?
    Last edited by wysota; 1st January 2012 at 20:16.
    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.


  7. #7
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: foreach or alike

    Sorry but would you be able to show an example of subclassing a model that seems like the perfect way to go

  8. #8
    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: foreach or alike

    Don't you know how to implement a subclass in C++?

    Qt Code:
    1. class MyModel : public QSqlQueryModel {
    2. public:
    3. MyModel(...) : QSqlQueryModel(...) {}
    4.  
    5. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const {
    6. // put your stuff here
    7. }
    8. };
    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. foreach error while compiling
    By smanoj in forum Newbie
    Replies: 4
    Last Post: 24th November 2011, 05:32
  2. QSplitter Skype-alike
    By davideanastasia in forum Newbie
    Replies: 3
    Last Post: 2nd June 2011, 14:26
  3. foreach QTextEdit in Layout
    By slc in forum Qt Programming
    Replies: 1
    Last Post: 2nd September 2010, 00:45
  4. lifetime of foreach
    By BalaQT in forum Newbie
    Replies: 4
    Last Post: 4th March 2010, 15:55
  5. Foreach performance
    By jano_alex_es in forum General Programming
    Replies: 2
    Last Post: 17th November 2009, 13:26

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.