Results 1 to 2 of 2

Thread: passing the wrong signal

  1. #1
    Join Date
    Mar 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default passing the wrong signal

    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?

    Qt Code:
    1. void MainWindow::createDockWindows()
    2. {
    3. PGresult * result;
    4.  
    5. QDockWidget *dock = new QDockWidget(tr("Description"), this);
    6. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea);
    7. taskDescription = new QTextBrowser(dock);
    8. taskDescription->setHtml("Lorem ipsum dolor sit amet");
    9. dock->setWidget(taskDescription);
    10. addDockWidget(Qt::RightDockWidgetArea, dock);
    11. viewMenu->addAction(dock->toggleViewAction());
    12.  
    13. dock = new QDockWidget(tr("Tasks"), this);
    14. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea);
    15. taskList = new QListWidget(dock);
    16. taskId = new QListWidget;
    17.  
    18. result = newGlmdb.query("SELECT name, tid FROM tasks WHERE eid = 1 AND archived = 'f' ORDER BY tid");
    19.  
    20. if (PQresultStatus(result) == PGRES_TUPLES_OK)
    21. {
    22. int numTuples = PQntuples(result);
    23. for (int i = 0; i < numTuples; i++)
    24. {
    25. tasks[i][0] = PQgetvalue(result, i, 0);
    26. tasks[i][1] = PQgetvalue(result, i, 1);
    27. taskList->addItems(QStringList() << tasks[i][0]);
    28. taskId->addItem(tasks[i][1]);
    29. }
    30. }
    31.  
    32. dock->setWidget(taskList);
    33. addDockWidget(Qt::RightDockWidgetArea, dock);
    34. viewMenu->addAction(dock->toggleViewAction());
    35.  
    36. connect(taskList, SIGNAL(currentTextChanged(const QString &)),
    37. this, SLOT(updateDescription(const QString &)));
    38. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: passing the wrong signal

    Maybe QListWidget::currentRowChanged() signal will suit you better?

Similar Threads

  1. What's wrong with my actions???
    By fullmetalcoder in forum Qt Programming
    Replies: 6
    Last Post: 4th March 2007, 19:49
  2. Signal and slots
    By villy in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 11:10
  3. Replies: 2
    Last Post: 17th May 2006, 22:01
  4. no such signal QListBox::currentChanged()
    By jopie bakker in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 16:17
  5. No such signal...
    By chaimar in forum Qt Programming
    Replies: 12
    Last Post: 24th January 2006, 23:33

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
  •  
Qt is a trademark of The Qt Company.