LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-29-2008, 12:34 PM   #1
Luis Navarro
LQ Newbie
 
Registered: Dec 2008
Location: Brazil, Parana State, portuguese language.
Distribution: Fedora V8
Posts: 4

Rep: Reputation: 0
C++ Qt QlistView signals


C++ Qt QlistView signals
************************
My problem is about knowing in what 'item' of a ListView the user has clicked.
I tried with the following program (3 modules plus a Widget from QtDesigner (ui_wex50.h).)

//----------------------------------------------------------------
// wex50.h
//----------------------------------------------------------------
#include <QApplication>

#include <QListWidget>
#include "ui_wex50.h"
#ifndef GRMEM910_H
#define GRMEM910_H
class mywindow : public QWidget, private Ui::Form
{ Q_OBJECT
public: mywindow(QWidget *parent=0); };
//
class mylistWidget : public mywindow, QListWidget
{ public: mylistWidget(QListWidget *);
void myaction(QListWidgetItem *); };
#endif


//----------------------------------------------------------------
// wex50.cpp
//----------------------------------------------------------------
#include <QApplication>

#include <QListWidget>
#include <iostream>

#include "wex50.h"
using namespace std;

mywindow::mywindow(QWidget *)

{ setupUi(this);

QWidget *mywindow = new QWidget;
QListWidget *mylistWidget = new QListWidget(this);
mylistWidget->setGeometry(50,10,40,400);
new QListWidgetItem(tr("A"), mylistWidget);
new QListWidgetItem(tr("B"), mylistWidget);
new QListWidgetItem(tr("C"), mylistWidget);
new QListWidgetItem(tr("D"), mylistWidget);
new QListWidgetItem(tr("F"), mylistWidget);
new QListWidgetItem(tr("G"), mylistWidget);
new QListWidgetItem(tr("H"), mylistWidget);
new QListWidgetItem(tr("I"), mylistWidget);
new QListWidgetItem(tr("J"), mylistWidget);
new QListWidgetItem(tr("K"), mylistWidget);
new QListWidgetItem(tr("L"), mylistWidget);
new QListWidgetItem(tr("M"), mylistWidget);
new QListWidgetItem(tr("N"), mylistWidget);
new QListWidgetItem(tr("O"), mylistWidget);
new QListWidgetItem(tr("P"), mylistWidget);
new QListWidgetItem(tr("Q"), mylistWidget);
new QListWidgetItem(tr("R"), mylistWidget);
new QListWidgetItem(tr("S"), mylistWidget);
new QListWidgetItem(tr("T"), mylistWidget);
new QListWidgetItem(tr("U"), mylistWidget);
new QListWidgetItem(tr("V"), mylistWidget);
new QListWidgetItem(tr("X"), mylistWidget);
new QListWidgetItem(tr("Y"), mylistWidget);
new QListWidgetItem(tr("W"), mylistWidget);
new QListWidgetItem(tr("Z"), mylistWidget);

connect(mylistWidget, SIGNAL(itemClicked(QListWidgetItem *item)), this, SLOT(myaction(void)));

};

//
void mylistWidget::myaction(QListWidgetItem *item)
{ std::cout << item;
mywindow::close(); };


//----------------------------------------------------------------
// ex50.cpp
//----------------------------------------------------------------
#include <QApplication>

#include <QListWidget>
#include "wex50.h"
using namespace std;

int main( int argc, char **argv )
{ QApplication app(argc,argv);
mywindow *Form = new mywindow;
Form->show();
return app.exec(); };
//----------------------------------------------------------------


I've tried to change the signal to:

connect(mylistWidget, SIGNAL(selectionChanged()), this, SLOT(myaction(void)));

both signals were in the Qt documentation, but
when executing the program prints on the console:

Object::connect: No such signal QListWidget::itemClicked()
Object::connect: (receiver name: 'Form')

or

Object::connect: No such signal QListWidget::selectionChanged()
Object::connect: (receiver name: 'Form')

and doesn't recognize the click in the selected letter.

How do I can know what letter was clicked?
Please help me and I'll be gratefull.

Luis Navarro
 
Old 12-30-2008, 07:54 AM   #2
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 215

Rep: Reputation: 21
Hello.

O.K. you have more possibilities :
-take the signal < selectionChanged( QListViewItem * ) > so you get the item the user changed to.
-take the signal < selectionChanged () > and in the member you connected to read then what the current item is < QListViewItem * currentItem () >
-take the signal < void clicked ( QListViewItem * item ) but that means any mouse click, so you have to look what mousebutton is pressed.

It looks like you don't take QT-Designer to create your Widgets. There you get presented what signals you can use and where you can connect to.
The error you get is often because of signals with names, strings as value or the connected member is not in the same class and below. With parent-> you can connect to overlaying Widgets, just parents.

Good luck.
 
Old 12-30-2008, 12:43 PM   #3
Luis Navarro
LQ Newbie
 
Registered: Dec 2008
Location: Brazil, Parana State, portuguese language.
Distribution: Fedora V8
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks a lot.
I'm goig to study your proposition.
I'm, newcomer to linux and Qt (I'm learning by myself), even I have a medium experience in C++ Borland Builder for Windows. The Designer module refers itself to others details of my widget that I didn't include to resume the problem.
Thanks and Have a Happy New Year.

Quote:
Originally Posted by bastl View Post
Hello.

O.K. you have more possibilities :
-take the signal < selectionChanged( QListViewItem * ) > so you get the item the user changed to.
-take the signal < selectionChanged () > and in the member you connected to read then what the current item is < QListViewItem * currentItem () >
-take the signal < void clicked ( QListViewItem * item ) but that means any mouse click, so you have to look what mousebutton is pressed.

It looks like you don't take QT-Designer to create your Widgets. There you get presented what signals you can use and where you can connect to.
The error you get is often because of signals with names, strings as value or the connected member is not in the same class and below. With parent-> you can connect to overlaying Widgets, just parents.

Good luck.
 
  


Reply

Tags
c++, qt


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with QListView binarybob0001 Programming 1 11-27-2007 12:05 AM
signals lamtab Programming 1 11-17-2007 12:51 PM
QListView help elvislu Programming 2 05-17-2005 10:37 AM
QListview in Qt shivaligupta Programming 1 01-13-2005 04:19 PM
how to connect my signal with standart (Qt(QListView)) stpg Programming 1 07-05-2004 08:22 AM


All times are GMT -5. The time now is 05:23 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration