Qt-jambi-interest Archive, January 2007
Signal/Slots issues
Message 1 in thread
Hi all,
I have a simple app which loads a file and displays it with qt.
There is a thread which checks if the file changes and if yes it calls
the openFile
method of the main class. However I sometimes got the following error:
QObject::connect: Cannot queue arguments of type 'QModelIndex'
(Make sure 'QModelIndex' is registed using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QModelIndex'
(Make sure 'QModelIndex' is registed using qRegisterMetaType().)
I was told to use Signals/Slots instead of accessing the method from
another thread. So I tried the following:
In the thread I define the following:
private Signal1<String> updateFile;
updateFile.connect(logViewer, "openFile(String)"); (in the constructor of it)
and in the method which checks the file:
updateFile.emit(path);
However I always get a nullPointerException. I also tried defining the
Signal in the main class but it did not work either. There are 2
methods with the name openFile, one with a string as arg and one w/o
args I want to call the one with the String.
Of course I also had a look at the documentation, but this was not
very helpful, since it was all in c++..
Nils
Message 2 in thread
Hi, Nils.
Nils wrote:
> In the thread I define the following:
>
> private Signal1<String> updateFile;
> updateFile.connect(logViewer, "openFile(String)"); (in the constructor
> of it)
> and in the method which checks the file:
> updateFile.emit(path);
>
> However I always get a nullPointerException. I also tried defining the
Where is your NullPointerException originating from? And how exactly
does your thread class look?
The following code should work:
class QObjectSubclass extends QObject {
private Signal1<String> updateFile = new Signal1<String>();
private QWidget logViewer = new QWidget(this);
public QObjectSubclass() {
updateFile(logViewer, "openFile(String)");
}
}
Note that I have added initialization of the Signal1-object. This is not
strictly necessary in TP3, but it will become required in the upcoming
Beta, so for more compatible code, you should add this part.
> Of course I also had a look at the documentation, but this was not
> very helpful, since it was all in c++..
>
Yes, there should be a section explaining signals and slots in Java.
However, in the meantime, it may be helpful to look at the documentation
for the examples, as they are all written in Java:
http://doc.trolltech.com/qtjambi-1.0/com/trolltech/qt/qtjambi-examples.html
best regards,
Eskil