You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, January 10th 2011, 9:18pm

Model Test (Tree View) for Kdevelop/KDE or only qt?

Hi all,

After alot of trying and fiddling with QAbstractItemModel I finally got my application to compile and run.
However there is still a bug in it.
I get this result:

Source code

1
2
3
4
5
So if I have 2 top level nodes:
node1
  node1
 	node1
node2

Of course this is not what I want.
It seems that this returns the wrong entry:

Source code

1
2
3
4
5
6
7
8
Directory *DirectoryModel::directoryFromIndex(const QModelIndex &index) const
{
  if(index.isValid()) {
	return static_cast<Directory *>(index.internalPointer());
  } else {
	return rootDirectory;
  }
}


I then found this: http://developer.qt.nokia.com/wiki/Model_Test

Now I wonder if I could use this in KDevelop/KDE for troubleshooting what I did wrong.
And if I can, how do I use it? (they are talking about a .pro file however I don't have this in my structure; I tried to put it in CMakeLists.txt and that didn't work either).

Or does someone knows another testing class for this?

Thanks alot in advance!

2

Tuesday, January 11th 2011, 3:00pm

Somebody pointed out that this is not specific to any IDE.

So I copied the files.
However they are talking about modeltest.pri and I can't seem to find it.

3

Wednesday, January 12th 2011, 10:03am

I am a little bit further:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#
Linking CXX executable diskspacefree
#
cd /home/gvm/projects/DiskspaceFree/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/diskspacefree.dir/link.txt --verbose=1                                                          
#
/usr/bin/c++    -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-check-new -fno-common -Woverloaded-virtual -fno-threadsafe-statics -fvisibility=hidden -fvisibility-inlines-hidden -g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline  -Wl,--enable-new-dtags  CMakeFiles/diskspacefree.dir/diskspacefree_automoc.o CMakeFiles/diskspacefree.dir/directorymodel.o CMakeFiles/diskspacefree.dir/directoryparser.o CMakeFiles/diskspacefree.dir/directory.o CMakeFiles/diskspacefree.dir/diskspacefree.o CMakeFiles/diskspacefree.dir/main.o CMakeFiles/diskspacefree.dir/diskspacefreeview.o CMakeFiles/diskspacefree.dir/modeltest.o CMakeFiles/diskspacefree.dir/dynamictreemodel.o CMakeFiles/diskspacefree.dir/settings.o  -o diskspacefree -rdynamic -L/usr/lib64/qt4 /usr/lib64/libkdeui.so.5.4.0 /usr/lib64/libkdecore.so.5.4.0 /usr/lib64/qt4/libQtDBus.so /usr/lib64/qt4/libQtCore.so -lpthread /usr/lib64/qt4/libQtSvg.so /usr/lib64/qt4/libQtGui.so -Wl,-rpath,/usr/lib64/qt4:::::::::::::::::
#
CMakeFiles/diskspacefree.dir/modeltest.o: In function `ModelTest::index()':
#
/home/gvm/projects/DiskspaceFree/src/modeltest.cpp:228: undefined reference to `QTest::qVerify(bool, char const*, char const*, char const*, int)'
#
/home/gvm/projects/DiskspaceFree/src/modeltest.cpp:229: undefined reference to `QTest::qVerify(bool, char const*, char const*, char const*, int)'
#
/home/gvm/projects/DiskspaceFree/src/modeltest.cpp:230: undefined reference to `QTest::qVerify(bool, char const*, char const*, char const*, int)'
#
/home/gvm/projects/DiskspaceFree/src/modeltest.cpp:239: undefined reference to `QTest::qVerify(bool, char const*, char const*, char const*, int)'
#
/home/gvm/projects/DiskspaceFree/src/modeltest.cpp:240: undefined reference to `QTest::qVerify(bool, char const*, char const*, char const*, int)'
#
CMakeFiles/diskspacefree.dir/modeltest.o:/home/gvm/projects/DiskspaceFree/src/modeltest.cpp:245: more undefined references to `QTest::qVerify(bool, char const*, char const*, char const*, int)' follow
#
collect2: ld returned 1 exit status
#
make[2]: *** [src/diskspacefree] Error 1
#
make[2]: Leaving directory `/home/gvm/projects/DiskspaceFree/build'
#
make[1]: *** [src/CMakeFiles/diskspacefree.dir/all] Error 2
#
make[1]: Leaving directory `/home/gvm/projects/DiskspaceFree/build'
#
make: *** [all] Error 2

4

Wednesday, January 12th 2011, 12:40pm

I have been pointed in the wrong direction for a long time :(
Many hours later, I figured they were expecting me to use qmake and not cmake.

So I posted on the kde forums and someone told me I needed this:

Source code

1
target_link_library(testname .... ${QT_QTTEST_LIBRARY}

That fixed the linking issue.
I hope it helps someone in the future.

IMPORTANT: first check wether you are using qmake (uses .pro file) or cmake (uses CMakeLists.txt)