Results 1 to 3 of 3

Thread: Search a solution for optimize my combobox signal

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Search a solution for optimize my combobox signal

    Hi everybody.

    I have in my MainWindow 2 Comboboxes with values from a database.
    One Combobox should call the function searchSongbyArtist() and the other one getPlaylist() by changing the current index

    Both functions insert values to my listView(see code).Depends on wich combobox the user change the
    currentIndex, the values are diferent on my listview.

    After changing a index from a combobox i want that the other combobox is clean or without text.
    But my problem is that if i change the index from the other combobox the function searchSongbyArtist()
    or getPlaylist() start 2 times because the signal call it and i change the currentItem( ui.album_cb->setCurrentItem(0))
    on the other function.

    My idea is:
    - the use change the current item from combobox1
    - change index from combobox2 to position 0. (0 is a empty text)
    - insert values to my listview

    Have i a solution?

    Qt Code:
    1. connect(ui.artist_cb, SIGNAL(currentIndexChanged (int)), this, SLOT(searchSongbyArtist()));
    2. connect(ui.playlistname_cb, SIGNAL(currentIndexChanged (int)), this, SLOT(getPlaylist()));
    3.  
    4. void MainWindow::searchSongbyArtist()
    5. {
    6.  
    7. ui.listView->clear();
    8. ui.label->clear();
    9. ui.songname_le->clear();
    10.  
    11. //If i call this my function start 2 times. I want the the combobox is clean
    12. ui.album_cb->setCurrentItem(0);
    13. ui.playlistname_cb->setCurrentItem(0);
    14.  
    15. QString artist = ui.artist_cb->currentText();
    16. QSqlQuery select_count("SELECT song_tbl.song, artist_tbl.artist, album_tbl.album, style_tbl.style, album_tbl.picture, "
    17. "song_tbl.soundpath, song_tbl.song_id FROM style_tbl INNER JOIN (artist_tbl INNER JOIN "
    18. "(album_tbl INNER JOIN song_tbl ON album_tbl.album_id = song_tbl.album_id) ON "
    19. "artist_tbl.artist_id = album_tbl.artist_id) ON style_tbl.style_id = album_tbl.style_id "
    20. "WHERE artist_tbl.artist = '" + artist + "'");
    21. while(select_count.next())
    22. {
    23. QString song = select_count.value(0).toString();
    24. QString artist = select_count.value(1).toString();
    25. QString album = select_count.value(2).toString();
    26. QString style = select_count.value(3).toString();
    27. QString picture = select_count.value(4).toString();
    28. QString soundpath = select_count.value(5).toString();
    29. QString song_id = select_count.value(6).toString();
    30.  
    31. ui.listView->insertItem(
    32. new Q3ListViewItem (ui.listView, song, artist, album, style, picture, soundpath, song_id));
    33. }
    34. if (ui.listView->childCount() > 0)
    35. {
    36. ui.listView->setFocus();
    37. ui.listView->setSelected((ui.listView->firstChild()), true);
    38. }
    39.  
    40. }
    41.  
    42. void MainWindow::getPlaylist()
    43. {
    44. ui.listView->setSortColumn(-1);
    45. ui.listView->clear();
    46. ui.label->clear();
    47. ui.songname_le->clear();
    48.  
    49. //If i call this my function start 2 times. I want the the combobox is clean
    50. ui.album_cb->setCurrentItem(0);
    51. ui.artist_cb->setCurrentItem(0);
    52.  
    53. QString playlistname = ui.playlistname_cb->currentText();
    54. QSqlQuery select_count("SELECT song_tbl.song, artist_tbl.artist, album_tbl.album, style_tbl.style, "
    55. "album_tbl.picture, song_tbl.soundpath, song_tbl.song_id FROM style_tbl INNER JOIN ((artist_tbl INNER JOIN "
    56. "(album_tbl INNER JOIN song_tbl ON album_tbl.album_id = song_tbl.album_id) ON "
    57. "artist_tbl.artist_id = album_tbl.artist_id) INNER JOIN (playlistname_tbl INNER JOIN "
    58. "playlist_tbl ON playlistname_tbl.playlistname_id = playlist_tbl.playlistname_id) ON "
    59. "song_tbl.song_id = playlist_tbl.song_id) ON style_tbl.style_id = album_tbl.style_id "
    60. "WHERE playlistname_tbl.playlistname = '" + playlistname + "' order by playlist_id desc");
    61.  
    62. while(select_count.next())
    63. {
    64. QString song = select_count.value(0).toString();
    65. QString artist = select_count.value(1).toString();
    66. QString album = select_count.value(2).toString();
    67. QString style = select_count.value(3).toString();
    68. QString picture = select_count.value(4).toString();
    69. QString soundpath = select_count.value(5).toString();
    70. QString song_id = select_count.value(6).toString();
    71. ui.listView->insertItem(
    72. new Q3ListViewItem (ui.listView, song, artist, album, style, picture, soundpath, song_id));
    73. }
    74. if (ui.listView->childCount() > 0)
    75. {
    76. ui.listView->setFocus();
    77. ui.listView->setSelected((ui.listView->firstChild()), true);
    78. }
    79.  
    80. }
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Search a solution for optimize my combobox signal

    If you use the activated slot, instead of currentIndexChanged you only get a signal when the user changes the index and not when you change it programmatically - that could help you.

  3. The following user says thank you to e8johan for this useful post:

    raphaelf (12th October 2006)

  4. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Search a solution for optimize my combobox signal

    Hi e8johan!!

    It works perfect
    Think DigitalGasoline

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.