PDA

View Full Version : Search a solution for optimize my combobox signal



raphaelf
12th October 2006, 08:58
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? :crying:



connect(ui.artist_cb, SIGNAL(currentIndexChanged (int)), this, SLOT(searchSongbyArtist()));
connect(ui.playlistname_cb, SIGNAL(currentIndexChanged (int)), this, SLOT(getPlaylist()));

void MainWindow::searchSongbyArtist()
{

ui.listView->clear();
ui.label->clear();
ui.songname_le->clear();

//If i call this my function start 2 times. I want the the combobox is clean
ui.album_cb->setCurrentItem(0);
ui.playlistname_cb->setCurrentItem(0);

QString artist = ui.artist_cb->currentText();
QSqlQuery select_count("SELECT song_tbl.song, artist_tbl.artist, album_tbl.album, style_tbl.style, album_tbl.picture, "
"song_tbl.soundpath, song_tbl.song_id FROM style_tbl INNER JOIN (artist_tbl INNER JOIN "
"(album_tbl INNER JOIN song_tbl ON album_tbl.album_id = song_tbl.album_id) ON "
"artist_tbl.artist_id = album_tbl.artist_id) ON style_tbl.style_id = album_tbl.style_id "
"WHERE artist_tbl.artist = '" + artist + "'");
while(select_count.next())
{
QString song = select_count.value(0).toString();
QString artist = select_count.value(1).toString();
QString album = select_count.value(2).toString();
QString style = select_count.value(3).toString();
QString picture = select_count.value(4).toString();
QString soundpath = select_count.value(5).toString();
QString song_id = select_count.value(6).toString();

ui.listView->insertItem(
new Q3ListViewItem (ui.listView, song, artist, album, style, picture, soundpath, song_id));
}
if (ui.listView->childCount() > 0)
{
ui.listView->setFocus();
ui.listView->setSelected((ui.listView->firstChild()), true);
}

}

void MainWindow::getPlaylist()
{
ui.listView->setSortColumn(-1);
ui.listView->clear();
ui.label->clear();
ui.songname_le->clear();

//If i call this my function start 2 times. I want the the combobox is clean
ui.album_cb->setCurrentItem(0);
ui.artist_cb->setCurrentItem(0);

QString playlistname = ui.playlistname_cb->currentText();
QSqlQuery select_count("SELECT song_tbl.song, artist_tbl.artist, album_tbl.album, style_tbl.style, "
"album_tbl.picture, song_tbl.soundpath, song_tbl.song_id FROM style_tbl INNER JOIN ((artist_tbl INNER JOIN "
"(album_tbl INNER JOIN song_tbl ON album_tbl.album_id = song_tbl.album_id) ON "
"artist_tbl.artist_id = album_tbl.artist_id) INNER JOIN (playlistname_tbl INNER JOIN "
"playlist_tbl ON playlistname_tbl.playlistname_id = playlist_tbl.playlistname_id) ON "
"song_tbl.song_id = playlist_tbl.song_id) ON style_tbl.style_id = album_tbl.style_id "
"WHERE playlistname_tbl.playlistname = '" + playlistname + "' order by playlist_id desc");

while(select_count.next())
{
QString song = select_count.value(0).toString();
QString artist = select_count.value(1).toString();
QString album = select_count.value(2).toString();
QString style = select_count.value(3).toString();
QString picture = select_count.value(4).toString();
QString soundpath = select_count.value(5).toString();
QString song_id = select_count.value(6).toString();
ui.listView->insertItem(
new Q3ListViewItem (ui.listView, song, artist, album, style, picture, soundpath, song_id));
}
if (ui.listView->childCount() > 0)
{
ui.listView->setFocus();
ui.listView->setSelected((ui.listView->firstChild()), true);
}

}

e8johan
12th October 2006, 09:05
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.

raphaelf
12th October 2006, 09:17
Hi e8johan!!

It works perfect :p