PDA

View Full Version : passing the wrong signal



veilig
28th March 2007, 21:30
I'm new to QT, never used it before and I'm trying to solve a problem
I'm having. (its probably easy) but I've been banging
my head on it for a while

here's the problem:
I have two dock widgets in an app. One holds a QListWidget which I fill
up with tasks from a Database query. The other holds a QTextBrowser
which I used to display the task description of the currently selected
task in the QListWidget. now I make a signal to connect the task list
to an updateDescription slot and I would like to pass an int which
represents a task id(tid). I can then use that int to query for the
newly selected task's description and update the QTextBrowser widget
with the new description.

my problem I'm running into is, I can't figure out how to connect the
ListWidget to the slot so it passes the tid of the new task instead of
passing the name (a string) of the newly selected task in the task list.

the array tasks[i][1] holds the value of the tid I need to pass into
updateDescription, but how can I associate that tid
with the list item selected?



void MainWindow::createDockWindows()
{
PGresult * result;

QDockWidget *dock = new QDockWidget(tr("Description"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea);
taskDescription = new QTextBrowser(dock);
taskDescription->setHtml("Lorem ipsum dolor sit amet");
dock->setWidget(taskDescription);
addDockWidget(Qt::RightDockWidgetArea, dock);
viewMenu->addAction(dock->toggleViewAction());

dock = new QDockWidget(tr("Tasks"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea);
taskList = new QListWidget(dock);
taskId = new QListWidget;

result = newGlmdb.query("SELECT name, tid FROM tasks WHERE eid = 1 AND archived = 'f' ORDER BY tid");

if (PQresultStatus(result) == PGRES_TUPLES_OK)
{
int numTuples = PQntuples(result);
for (int i = 0; i < numTuples; i++)
{
tasks[i][0] = PQgetvalue(result, i, 0);
tasks[i][1] = PQgetvalue(result, i, 1);
taskList->addItems(QStringList() << tasks[i][0]);
taskId->addItem(tasks[i][1]);
}
}

dock->setWidget(taskList);
addDockWidget(Qt::RightDockWidgetArea, dock);
viewMenu->addAction(dock->toggleViewAction());

connect(taskList, SIGNAL(currentTextChanged(const QString &)),
this, SLOT(updateDescription(const QString &)));
}

jacek
28th March 2007, 22:03
Maybe QListWidget::currentRowChanged() signal will suit you better?