Results 1 to 8 of 8

Thread: How to get data from sqlquery that result 3 columns in a row and show only 1 Colum

  1. #1
    Join Date
    May 2009
    Posts
    83

    Default How to get data from sqlquery that result 3 columns in a row and show only 1 Colum

    How to get data from sqlquery that result 3 columns in a row and show only 1 Colum and use the other columns data
    hello all
    im using QSqlQueryModel subclass to execute sql querys and populate them to tableview
    now i have simple sql query that results 3 columns/ fields in a row that invoked in the QSqlQueryModel subclass like this :

    Qt Code:
    1. QString query_local = "SELECT foo1,foo2,foo3 FROM tbl" ;
    2. QSqlQueryModel::setQuery(query_local, queryDB);
    To copy to clipboard, switch view to plain text mode 

    now i what to use the data from foo1 and foo 2 but display only foo3
    so in the end there will be only one column in the view per row.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to get data from sqlquery that result 3 columns in a row and show only 1 Colu

    Do yourself a favour... find an SQL tutorial. If you only want foo3 in the result then only list foo3. Assuming "use the data from foo1 and foo 2" means filtering on those columns then they appear in the WHERE clause.

  3. #3
    Join Date
    May 2009
    Posts
    83

    Default Re: How to get data from sqlquery that result 3 columns in a row and show only 1 Colu

    Hi
    sorry but English isn't my native language so i guess i have semantic errors .
    what i mean is that i need the data from foo1 and foo2 to use ( store in the Qt::UserRole as string)
    but display in the Qt:isplayRole the result of foo3.
    is it more clear ?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get data from sqlquery that result 3 columns in a row and show only 1 Colu

    RTFM and hint is QTableView::hideColumn

  5. #5
    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: How to get data from sqlquery that result 3 columns in a row and show only 1 Colu

    To avoid double answers: http://qt-project.org/forums/viewthread/15861/.
    Not so polite to ask the same question in different forums...

    EDIT: And here we go: http://qt-project.org/forums/viewthread/15795/.
    Menu -> Block User -> add!

  6. #6
    Join Date
    May 2009
    Posts
    83

    Default Re: How to get data from sqlquery that result 3 columns in a row and show only 1 Colu

    Thanks for the answer , but this dosn't work i set the table like this :
    Qt Code:
    1. m_pPlayListMiniItemDelegate =new PlayListMiniItemDelegate(this);
    2. ui->PlayListMini_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    3. ui->PlayListMini_tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    4. ui->PlayListMini_tableView->setItemDelegate(m_pPlayListMiniItemDelegate);
    5. ui->PlayListMini_tableView->setAlternatingRowColors(true);
    6. ui->PlayListMini_tableView->setModel(PlayListMiniSqlModel::instance());
    7. ui->PlayListMini_tableView->hideColumn(0);
    8. ui->PlayListMini_tableView->hideColumn(1);
    To copy to clipboard, switch view to plain text mode 
    and inside the PlayListMiniSqlModel::instance()
    i execute simple sql that returns 3 results in a row.
    "SELECT foo1,foo2,foo3 FROM tbl"
    the hide column 0,1 dosnt work i still see 3 column in raw.
    also i follow this tutorial :
    http://www.jwdougherty.com/content/q...ser-interfaces

  7. #7
    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: How to get data from sqlquery that result 3 columns in a row and show only 1 Colu

    Show us your model implementation, please.
    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.


  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to get data from sqlquery that result 3 columns in a row and show only 1 Colu

    Quote Originally Posted by umen View Post
    i execute simple sql that returns 3 results in a row.
    "SELECT foo1,foo2,foo3 FROM tbl"
    the hide column 0,1 dosnt work i still see 3 column in raw.
    Ah yes... and that is a problem because...?

Similar Threads

  1. Replies: 3
    Last Post: 5th January 2011, 22:55
  2. qabstracttablemodel/qtableview: vector data columns
    By xyfix in forum Qt Programming
    Replies: 0
    Last Post: 15th September 2010, 12:51
  3. Replies: 2
    Last Post: 27th August 2009, 20:31
  4. QCcompleter , colum probelm
    By deepinlife in forum Qt Programming
    Replies: 7
    Last Post: 10th April 2008, 07:46
  5. Replies: 1
    Last Post: 21st March 2006, 12:54

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.