Qt-interest Archive, December 2007
QTreeView and QItemSelectionModel does not show signal
Message 1 in thread
Hi group,
I am investigating the MVC model of Qt. I need this for a larger
project. Now my problems.
I have the following code, which translates nicely however I get a
runtime error on a missing signal.
The code is in the attachments. The runtime-error message is as follows:
node-14:~/qt-designer/tutorial/dirmodel> ./dirmodel
Object::connect: No such signal
QTreeView::selectionChanged(QItemSelection&,QItemSelection&)
I used various signals of QItemSelectionModel or QTreeView: always the
same error!
A hint would be nice.
tia
Jörg
######################################################################
######################################################################
# Automatically generated by qmake (2.01a) Sa Dez 1 19:28:17 2007
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += testclass.h
SOURCES += main.cpp testclass.cpp
/***************************************************************************
/***************************************************************************
* (C) 2007 IBK-Consult, D-31228 Peine
* trial model for investigation of QT-model "Dirinfo" to be used in class
* readFile.cpp/h
*
* created: JK 20071129 from code in QT-documentation on "dirinfo in Dir View Example"
* mod.: JK
****************************************************************************/
#include <QApplication>
#include <QSplitter>
#include <QDirModel>
#include <QTreeView>
#include <QListView>
#include <QDir>
#include <testclass.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CTestClass *test = new CTestClass ;
QSplitter *splitter = new QSplitter;
// here we get ready with our model - now configure it:
QDirModel *model = new QDirModel;
model->setFilter( QDir::AllEntries | QDir::NoDotAndDotDot ) ;
QTreeView *tree = new QTreeView(splitter);
tree->setModel(model);
// here we set our ROOT (where the display begins) to be displayed:
tree->setRootIndex(model->index( "\\" ));
QItemSelectionModel *selectionModel = tree->selectionModel() ;
QModelIndex topLeft;
QModelIndex bottomRight;
splitter->setWindowTitle("View onto the directory model");
splitter->show();
QObject::connect( tree, SIGNAL( selectionChanged( QItemSelection &, QItemSelection & ) ),
test, SLOT( CTestClass::itemClicked( QItemSelection &, QItemSelection & ) ),
Qt::DirectConnection ) ;
return app.exec();
}
#############################################################################
#############################################################################
# Makefile for building: dirmodel
# Generated by qmake (2.01a) (Qt 4.2.1) on: Sa Dez 1 19:28:21 2007
# Project: dirmodel.pro
# Template: app
# Command: /usr/bin/qmake -unix -o Makefile dirmodel.pro
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
LEX = flex
YACC = yacc
DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
LEXFLAGS =
YACCFLAGS = -d
INCPATH = -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -I. -I.
LINK = g++
LFLAGS =
LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -L/usr/lib -L/usr/X11R6/lib -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXfixes -lXcursor -lXinerama -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -ldl -lpthread
AR = ar cqs
RANLIB =
QMAKE = /usr/bin/qmake
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
COPY_FILE = $(COPY)
COPY_DIR = $(COPY) -r
INSTALL_FILE = install -m 644 -p
INSTALL_DIR = $(COPY_DIR)
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE = rm -f
SYMLINK = ln -sf
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
####### Output directory
OBJECTS_DIR = ./
####### Files
SOURCES = main.cpp \
testclass.cpp moc_testclass.cpp
OBJECTS = main.o \
testclass.o \
moc_testclass.o
DIST = /usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/g++.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/release.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/qt.prf \
/usr/share/qt4/mkspecs/features/unix/thread.prf \
/usr/share/qt4/mkspecs/features/moc.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
dirmodel.pro
QMAKE_TARGET = dirmodel
DESTDIR =
TARGET = dirmodel
first: all
####### Implicit rules
.SUFFIXES: .o .c .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
####### Build rules
all: Makefile $(TARGET)
$(TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
Makefile: dirmodel.pro /usr/share/qt4/mkspecs/default/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/g++.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/release.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/qt.prf \
/usr/share/qt4/mkspecs/features/unix/thread.prf \
/usr/share/qt4/mkspecs/features/moc.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
/usr/lib/libQtGui.prl \
/usr/lib/libQtCore.prl
$(QMAKE) -unix -o Makefile dirmodel.pro
/usr/share/qt4/mkspecs/common/unix.conf:
/usr/share/qt4/mkspecs/common/g++.conf:
/usr/share/qt4/mkspecs/common/linux.conf:
/usr/share/qt4/mkspecs/qconfig.pri:
/usr/share/qt4/mkspecs/features/qt_functions.prf:
/usr/share/qt4/mkspecs/features/qt_config.prf:
/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
/usr/share/qt4/mkspecs/features/default_pre.prf:
/usr/share/qt4/mkspecs/features/release.prf:
/usr/share/qt4/mkspecs/features/default_post.prf:
/usr/share/qt4/mkspecs/features/warn_on.prf:
/usr/share/qt4/mkspecs/features/qt.prf:
/usr/share/qt4/mkspecs/features/unix/thread.prf:
/usr/share/qt4/mkspecs/features/moc.prf:
/usr/share/qt4/mkspecs/features/resources.prf:
/usr/share/qt4/mkspecs/features/uic.prf:
/usr/lib/libQtGui.prl:
/usr/lib/libQtCore.prl:
qmake: FORCE
@$(QMAKE) -unix -o Makefile dirmodel.pro
dist:
@$(CHK_DIR_EXISTS) .tmp/dirmodel1.0.0 || $(MKDIR) .tmp/dirmodel1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/dirmodel1.0.0/ && $(COPY_FILE) --parents testclass.h .tmp/dirmodel1.0.0/ && $(COPY_FILE) --parents main.cpp testclass.cpp .tmp/dirmodel1.0.0/ && (cd `dirname .tmp/dirmodel1.0.0` && $(TAR) dirmodel1.0.0.tar dirmodel1.0.0 && $(COMPRESS) dirmodel1.0.0.tar) && $(MOVE) `dirname .tmp/dirmodel1.0.0`/dirmodel1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/dirmodel1.0.0
yaccclean:
lexclean:
clean:compiler_clean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Sub-libraries
distclean: clean
-$(DEL_FILE) $(TARGET)
-$(DEL_FILE) Makefile
/usr/bin/moc:
(cd $(QTDIR)/src/tools/moc && $(MAKE))
mocclean: compiler_moc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
compiler_moc_header_make_all: moc_testclass.cpp
compiler_moc_header_clean:
-$(DEL_FILE) moc_testclass.cpp
moc_testclass.cpp: testclass.h \
/usr/bin/moc
/usr/bin/moc $(DEFINES) $(INCPATH) testclass.h -o moc_testclass.cpp
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_image_collection_clean compiler_moc_source_clean compiler_uic_clean
####### Compile
main.o: main.cpp testclass.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
testclass.o: testclass.cpp testclass.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o testclass.o testclass.cpp
moc_testclass.o: moc_testclass.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_testclass.o moc_testclass.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:
/***************************************************************************
/***************************************************************************
* (C) 2007 IBK-Consult, D-31228 Peine
* trial model for investigation of QT-model "Dirinfo" to be used in class
* readFile.cpp/h
*
* created: JK 20071129 from code in QT-documentation on "dirinfo in Dir View Example"
* mod.: JK
****************************************************************************/
#include <iostream>
#include <testclass.h>
CTestClass::CTestClass( void ){
}
CTestClass::~CTestClass( void ){
}
void CTestClass::itemClicked( QItemSelection & index, QItemSelection & previous ){
index = index ; previous = previous ;
std::cout << "Index = \n" << std::endl ;
}
/***************************************************************************
/***************************************************************************
* (C) 2007 IBK-Consult, D-31228 Peine
* trial model for investigation of QT-model "Dirinfo" to be used in class
* readFile.cpp/h
*
* created: JK 20071129 from code in QT-documentation on "dirinfo in Dir View Example"
* mod.: JK
****************************************************************************/
#ifndef TEST_CLASS_H
#define TEST_CLASS_H
#include <QObject>
#include <QModelIndex>
#include <QItemSelection>
class CTestClass : public QObject {
Q_OBJECT
public:
CTestClass();
~CTestClass() ;
private slots:
void itemClicked( QItemSelection &, QItemSelection & ) ;
} ;
#endif
Message 2 in thread
You might want to try a debugger... rather then just running it from the command line...
However, the issue is selectionChanged is NOT a signal of the view.. It's a signal of the selectionModel
Rather then connecting to the view... connect to the views selectionModel()
QObject::connect( tree->selectionModel(), SIGNAL( selectionChanged( QItemSelection &, QItemSelection & ) ),
test, SLOT( CTestClass::itemClicked( QItemSelection &, QItemSelection & ) ),
Qt::DirectConnection ) ;
Also, you don't need the CTestClass::itemClicked it knows the class from the target class
Scott
> -----Original Message-----
> From: Ionathan [mailto:joerg-at-ibk@xxxxxx]
> Sent: Saturday, December 01, 2007 2:01 PM
> To: Qt-interest
> Subject: QTreeView and QItemSelectionModel does not show signal
>
> Hi group,
>
> I am investigating the MVC model of Qt. I need this for a larger
> project. Now my problems.
>
> I have the following code, which translates nicely however I get a
> runtime error on a missing signal.
> The code is in the attachments. The runtime-error message is as follows:
>
> node-14:~/qt-designer/tutorial/dirmodel> ./dirmodel
> Object::connect: No such signal
> QTreeView::selectionChanged(QItemSelection&,QItemSelection&)
>
> I used various signals of QItemSelectionModel or QTreeView: always the
> same error!
> A hint would be nice.
>
> tia
>
> Jörg
--
[ signature omitted ]
Message 3 in thread
Scott Aron Bloom schrieb:
> You might want to try a debugger... rather then just running it from the command line...
>
> However, the issue is selectionChanged is NOT a signal of the view.. It's a signal of the selectionModel
>
> Rather then connecting to the view... connect to the views selectionModel()
>
> QObject::connect( tree->selectionModel(), SIGNAL( selectionChanged( QItemSelection &, QItemSelection & ) ),
> test, SLOT( CTestClass::itemClicked( QItemSelection &, QItemSelection & ) ),
> Qt::DirectConnection ) ;
>
> Also, you don't need the CTestClass::itemClicked it knows the class from the target class
>
> Scott
>
>> I am investigating the MVC model of Qt. I need this for a larger
>> project. Now my problems.
>>
>> I have the following code, which translates nicely however I get a
>> runtime error on a missing signal.
>> The code is in the attachments. The runtime-error message is as follows:
>>
>> node-14:~/qt-designer/tutorial/dirmodel> ./dirmodel
>> Object::connect: No such signal
>> QTreeView::selectionChanged(QItemSelection&,QItemSelection&)
>>
>> I used various signals of QItemSelectionModel or QTreeView: always the
>> same error!
>> A hint would be nice.
>>
>> tia
>>
>> Jörg
>>
thank you, Scott ... however:
I corrected the connect - code and tried it with gdb ... same result:
41
42 splitter->setWindowTitle("View onto the directory model");
43 splitter->show();
44 QObject::connect( tree->selectionModel(),
(gdb)
45 SIGNAL(
selectionChanged( QItemSelection &, QItemSelection & ) ),
46 test, SLOT(
CTestClass::itemClicked( QItemSelection &, QItemSelection & ) ),
47 Qt::DirectConnection ) ;
48 return app.exec();
49
50 }
(gdb) b 43
Breakpoint 1 at 0x8049591: file main.cpp, line 43.
(gdb) run
Starting program: /home/kampmann/qt-designer/tutorial/dirmodel/dirmodel
Failed to read a valid object file image from memory.
[Thread debugging using libthread_db enabled]
[New Thread -1222243952 (LWP 3752)]
[Switching to Thread -1222243952 (LWP 3752)]
Breakpoint 1, main (argc=-1208476536, argv=0x8075ad8) at main.cpp:43
43 splitter->show();
(gdb) n
47 Qt::DirectConnection ) ;
(gdb)
Object::connect: No such signal
QItemSelectionModel::selectionChanged(QItemSelection&,QItemSelection&)
48 return app.exec();
(gdb) q
The program is running. Exit anyway? (y or n) y
--
[ signature omitted ]
Message 4 in thread
> 43 splitter->show();
> (gdb) n
> 47 Qt::DirectConnection )
;
> (gdb)
> Object::connect: No such signal
> QItemSelectionModel::selectionChanged(QItemSelection&,QItemSelection&)
> 48 return app.exec();
Try connecting to
selectionChanged ( const QItemSelection &, const QItemSelection &)
Scott
--
[ signature omitted ]
Message 5 in thread
> -----Original Message-----
> From: Scott Aron Bloom [mailto:Scott.Bloom@xxxxxxxxxxxx]
> Sent: Saturday, December 01, 2007 3:43 PM
> To: Ionathan; Qt-interest
> Subject: RE: QTreeView and QItemSelectionModel does not show signal
>
> > 43 splitter->show();
> > (gdb) n
> > 47 Qt::DirectConnection
)
> ;
> > (gdb)
> > Object::connect: No such signal
> >
QItemSelectionModel::selectionChanged(QItemSelection&,QItemSelection&)
> > 48 return app.exec();
>
>
> Try connecting to
> selectionChanged ( const QItemSelection &, const QItemSelection &)
>
> Scott
>
Changing the connection line to
QObject::connect( tree->selectionModel(), SIGNAL(
selectionChanged( const QItemSelection &, const QItemSelection & ) ),
test, SLOT( itemClicked( const
QItemSelection &, const QItemSelection & ) ),
Qt::DirectConnection ) ;
And it works fine...
Scott
--
[ signature omitted ]
Message 6 in thread
Scott Aron Bloom schrieb:
>
>> -----Original Message-----
>> From: Scott Aron Bloom [mailto:Scott.Bloom@xxxxxxxxxxxx]
>> Sent: Saturday, December 01, 2007 3:43 PM
>> To: Ionathan; Qt-interest
>> Subject: RE: QTreeView and QItemSelectionModel does not show signal
>>
>>
>>> 43 splitter->show();
>>> (gdb) n
>>> 47 Qt::DirectConnection
>>>
> )
>
>> ;
>>
>>> (gdb)
>>> Object::connect: No such signal
>>>
>>>
> QItemSelectionModel::selectionChanged(QItemSelection&,QItemSelection&)
>
>>> 48 return app.exec();
>>>
>> Try connecting to
>> selectionChanged ( const QItemSelection &, const QItemSelection &)
>>
>> Scott
>>
>>
> Changing the connection line to
> QObject::connect( tree->selectionModel(), SIGNAL(
> selectionChanged( const QItemSelection &, const QItemSelection & ) ),
> test, SLOT( itemClicked( const
> QItemSelection &, const QItemSelection & ) ),
> Qt::DirectConnection ) ;
>
> And it works fine...
>
> Scott
>
hurray - it works. for anybody who wants to have the code - look at
appendix ... now only some minor stuff is missing ...
thanks Scott
Jörg
######################################################################
######################################################################
# Automatically generated by qmake (2.01a) Sa Dez 1 19:28:17 2007
######################################################################
CONFIG += debug
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += testclass.h
SOURCES += main.cpp testclass.cpp
/***************************************************************************
/***************************************************************************
* (C) 2007 IBK-Consult, D-31228 Peine
* trial model for investigation of QT-model "Dirinfo" to be used in class
* readFile.cpp/h
*
* created: JK 20071129 from code in QT-documentation on "dirinfo in Dir View Example"
* mod.: JK
****************************************************************************/
#include <QApplication>
#include <QSplitter>
#include <QDirModel>
#include <QTreeView>
#include <QListView>
#include <QDir>
#include <testclass.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CTestClass *test = new CTestClass ;
QSplitter *splitter = new QSplitter;
// here we get ready with our model - now configure it:
QDirModel *model = new QDirModel;
model->setFilter( QDir::AllEntries | QDir::NoDotAndDotDot ) ;
QTreeView *treeVw = new QTreeView(splitter);
treeVw->setModel(model);
// here we set our ROOT (where the display begins) to be displayed:
treeVw->setRootIndex(model->index( "\\" ));
QItemSelectionModel *selectionModel = treeVw->selectionModel() ;
selectionModel = selectionModel ;
QModelIndex topLeft;
QModelIndex bottomRight;
splitter->setWindowTitle("View onto the directory model");
splitter->show();
/*
QObject::connect( treeVw->selectionModel(),
SIGNAL( selectionChanged( QItemSelection &, QItemSelection & ) ),
test,
SLOT( CTestClass::itemClicked( QItemSelection &, QItemSelection & ) ),
Qt::DirectConnection ) ;
*/
//from Qt-NG ... 20071202 (do not forget: testclass must also be modified!!):
QObject::connect( treeVw->selectionModel(),
SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
test,
SLOT( itemClicked( const QItemSelection &, const QItemSelection & ) ),
Qt::DirectConnection ) ;
return app.exec();
}
/***************************************************************************
/***************************************************************************
* (C) 2007 IBK-Consult, D-31228 Peine
* trial model for investigation of QT-model "Dirinfo" to be used in class
* readFile.cpp/h
*
* created: JK 20071129 from code in QT-documentation on "dirinfo in Dir View Example"
* mod.: JK
****************************************************************************/
#include <iostream>
#include <testclass.h>
CTestClass::CTestClass( void ){
}
CTestClass::~CTestClass( void ){
}
void CTestClass::itemClicked( const QItemSelection & index, const QItemSelection & previous ){
QItemSelection indexLocal = index ,
previousLocal = previous ;
std::cout << "Index = \n" << std::endl ;
}
/***************************************************************************
/***************************************************************************
* (C) 2007 IBK-Consult, D-31228 Peine
* trial model for investigation of QT-model "Dirinfo" to be used in class
* readFile.cpp/h
*
* created: JK 20071129 from code in QT-documentation on "dirinfo in Dir View Example"
* mod.: JK
****************************************************************************/
#ifndef TEST_CLASS_H
#define TEST_CLASS_H
#include <QObject>
#include <QModelIndex>
#include <QItemSelection>
class CTestClass : public QObject {
Q_OBJECT
public:
CTestClass();
~CTestClass() ;
private slots:
void itemClicked( const QItemSelection &, const QItemSelection & ) ;
} ;
#endif
Message 7 in thread
Hi,
I finally got what I wanted ... and: for those who might be interested
in the results I attach the - up to now - final solution, more or less
an extension to the "dirmodel" example within the Qt-docs.
Thank for everybody who helped me ...
Jörg
######################################################################
######################################################################
# Automatically generated by qmake (2.01a) Sa Dez 1 19:28:17 2007
######################################################################
CONFIG += debug
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += testclass.h
SOURCES += main.cpp testclass.cpp
/***************************************************************************
/***************************************************************************
* (C) 2007 IBK-Consult, D-31228 Peine
* trial model for investigation of QT-model "Dirinfo" to be used in class
* readFile.cpp/h
*
* created: JK 20071129 from code in QT-documentation on "dirinfo in Dir View Example"
* mod.: JK
****************************************************************************/
#include <QApplication>
#include <QSplitter>
//#include <QDirModel>
#include <QTreeView>
#include <QListView>
#include <QDir>
#include <testclass.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CTestClass *test = new CTestClass ;
QSplitter *splitter = new QSplitter;
// here we get ready with our model - now configure it:
test->model = new QDirModel;
test->model->setFilter( QDir::AllEntries | QDir::NoDotAndDotDot ) ;
QTreeView *treeVw = new QTreeView(splitter);
treeVw->setModel(test->model);
// here we set our ROOT (where the display begins) to be displayed:
treeVw->setRootIndex( test->model->index( "\\" ) );
QItemSelectionModel *selectionModel = treeVw->selectionModel() ;
selectionModel = selectionModel ;
//QModelIndex topLeft;
//QModelIndex bottomRight;
splitter->setWindowTitle("View onto the directory model");
splitter->show();
//from Qt-NG ... 20071202 (do not forget: testclass must also be modified!!):
QObject::connect( treeVw->selectionModel(),
SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
test,
SLOT( itemClicked( const QItemSelection &, const QItemSelection & ) ),
Qt::DirectConnection ) ;
return app.exec();
}
/***************************************************************************
/***************************************************************************
* (C) 2007 IBK-Consult, D-31228 Peine
* trial model for investigation of QT-model "Dirinfo" to be used in class
* readFile.cpp/h
*
* created: JK 20071129 from code in QT-documentation on "dirinfo in Dir View Example"
* mod.: JK
****************************************************************************/
#include <iostream>
#include <testclass.h>
CTestClass::CTestClass( void ){
}
CTestClass::~CTestClass( void ){
}
void CTestClass::itemClicked( const QItemSelection & selected, const QItemSelection & deselected ){
QItemSelection indexLocal = selected ,
previousLocal = deselected ;
QString indexString = "" ;
QVariant someText ;
QModelIndex index;
QModelIndexList items = selected.indexes(); // this is a list of selected items (jj,ii) (0,0),
// (0,1), (0,2) and (0,2) - there are 4 items
// for ii and as much as entries are in one layer
// for jj
static int jj , ii ; // after linkage has value 0
jj++ ; // counts every click on an non-selected item
foreach (index, items) {
QString text = QString("(%1,%2)").arg(index.row()).arg(index.column());
ii++ ;
someText = model->data(index) ;
QString contentText = someText.toString() ;
std::cout << "clicked "<<jj<< " times. Index = " << ii <<
" given index = "<< qPrintable( text ) << " content = "<<
qPrintable( contentText ) << std::endl ;
}
items = deselected.indexes();
/*
foreach (index, items)
model->setData(index, "");
*/
}
/***************************************************************************
/***************************************************************************
* (C) 2007 IBK-Consult, D-31228 Peine
* trial model for investigation of QT-model "Dirinfo" to be used in class
* readFile.cpp/h
*
* created: JK 20071129 from code in QT-documentation on "dirinfo in Dir View Example"
* mod.: JK
****************************************************************************/
#ifndef TEST_CLASS_H
#define TEST_CLASS_H
#include <QObject>
#include <QModelIndex>
#include <QItemSelection>
#include <QDirModel>
class CTestClass : public QObject {
Q_OBJECT
public:
CTestClass();
~CTestClass() ;
QDirModel *model ;
private slots:
void itemClicked( const QItemSelection &, const QItemSelection & ) ;
} ;
#endif
Message 8 in thread
Just a minor suggestion...
Have your test class derive itself from QItemSelectionModel
Then after the construction of the tree view, construct a new "testClassSelectionModel" and call treeView->setSelectionModel
This way the connectionthat caused you such grief is closer to where its being used and needed
Scott
> -----Original Message-----
> From: Ionathan [mailto:joerg-at-ibk@xxxxxx]
> Sent: Sunday, December 02, 2007 1:51 PM
> To: Qt-interest
> Subject: Re: QTreeView and QItemSelectionModel does not show signal -
> final success
>
> Hi,
>
> I finally got what I wanted ... and: for those who might be interested
> in the results I attach the - up to now - final solution, more or less
> an extension to the "dirmodel" example within the Qt-docs.
>
> Thank for everybody who helped me ...
>
> Jörg
--
[ signature omitted ]