[SOLVED]Update GUI from a no-QThread



  • Hi,
    I want to update the content of my GUI from an external thread.
    My thread is structured as follows:
    @class thread{
    void OnStartUp(){...}
    void Iterate(){...}
    void OnDataReceived(){...}
    void backgroundstart(){...}
    ..
    }@

    This thread can't be written as QThread(for many reasons...).
    How can I update the state of my GUI from a this thread?





  • I don't understand how i can use queued connection.
    My thread doesn't dispose the slots because it isn't a QObject. I've tried to inherit from QObject but i've obtained many errors.



  • Your class needs to inherit from QObject to be able to emit signals, yes.

    But it doesn't have to be a QThread. Just inheriting from QObject should be sufficient, I think.

    As you didn't say what errors you got, it's hard to say what was wrong...

    Note, however, that you'll have to include Q_OBJECT in your class definition and use the MOC!

    Please see:
    http://doc.qt.digia.com/qt/moc.html



  • I try what you say, but I obtained these errors:
    @
    build/Debug/GNU-Linux-x86/main.o: In function TestTime': .../QtApplicationMoc/main.cpp:16: undefined reference tovtable for TestTime'
    .../QtApplicationMoc/main.cpp:16: undefined reference to vtable for TestTime' build/Debug/GNU-Linux-x86/main.o: In function~TestTime':
    .../QtApplicationMoc/main.cpp:19: undefined reference to vtable for TestTime' .../QtApplicationMoc/main.cpp:19: undefined reference tovtable for TestTime'
    @

    I'll try to be more clear; my class is structured as follows:
    @
    class TestTime : public myClassThread , public QObject{
    Q_OBJECT
    public:
    TestTime(QObject * parent = 0){}
    ~TestTime(){}
    public:
    void onDataReceived(...){...}
    void onStartUp(){...}
    void iterate(){...}
    signals:
    void mySignal();
    public slots:
    void mySlot();
    };
    @
    To be sure, I've runed the qmake command but I've the same errors.



  • Did you add header file information to .pro file?

    @
    HEADERS += TestTime.h
    @



  • I think you need to "put QObject first":http://doc.qt.digia.com/4.7/moc.html#multiple-inheritance-requires-qobject-to-be-first in your class declaration, for moc to work properly.

    Thus, you need to change:
    @
    class TestTime : public myClassThread , public QObject
    @
    to this:
    @
    class TestTime : public QObject, public myClassThread
    @



  • Always put QObject at the bottom of the inheritance hierarchy, i.e. first



  • Probably better to just not multi-inherit from anything besides a pure interface.



  • Thank you to all! I've solved my first problem, but I've a new one.
    I use many libraries in my project, and some of them has the definition of the function in the file .h, for example:

    @
    file library.h

    namespace A{
    namespace B{
    bool funcion1(...){...}
    bool function2(...){...}
    }
    namespace C{
    ...
    }
    }
    @

    If I include this file in my project, I've many problems as follows:

    @
    build/Debug/GNU-Linux-x86/CommandControlApp.o: In function sign': /.../QtGuiC2/../ECL/includes/ecl_utils.h:29: multiple definition ofMS_topics'
    build/Debug/GNU-Linux-x86/main.o:/.../QtGuiC2/../ECL/includes/ecl_utils.h:29: first defined here
    build/Debug/GNU-Linux-x86/CommandControlApp.o: In function sign': /.../QtGuiC2/../ECL/includes/ecl_utils.h:30: multiple definition ofSSS_topics'
    build/Debug/GNU-Linux-x86/main.o:/.../QtGuiC2/../ECL/includes/ecl_utils.h:30: first defined here
    build/Debug/GNU-Linux-x86/CommandControlApp.o: In function intToString': /.../QtGuiC2/../ECL/includes/ecl_utils.h:46: multiple definition ofmessageType'
    build/Debug/GNU-Linux-x86/main.o:/.../QtGuiC2/../ECL/includes/ecl_utils.h:46: first defined here
    build/Debug/GNU-Linux-x86/moc_CommandControlApp.o: In function sign': /.../QtGuiC2/../ECL/includes/ecl_utils.h:29: multiple definition ofMS_topics'
    build/Debug/GNU-Linux-x86/main.o:/.../QtGuiC2/../ECL/includes/ecl_utils.h:29: first defined here
    build/Debug/GNU-Linux-x86/moc_CommandControlApp.o: In function sign': /.../QtGuiC2/../ECL/includes/ecl_utils.h:30: multiple definition ofSSS_topics'
    build/Debug/GNU-Linux-x86/main.o:/.../QtGuiC2/../ECL/includes/ecl_utils.h:30: first defined here
    build/Debug/GNU-Linux-x86/moc_CommandControlApp.o: In function intToString': /../QtGuiC2/../ECL/includes/ecl_utils.h:46: multiple definition ofmessageType'
    build/Debug/GNU-Linux-x86/main.o:/.../QtGuiC2/../ECL/includes/ecl_utils.h:46: first defined here
    collect2: ld returned 1 exit status
    @

    How can I solve it?
    How can I disable the -Wall option during the compile process?
    By searching in the web I find that the problem can be due by the moc... any suggestions?
    Thank you to all!



  • @/.../QtGuiC2/../ECL/includes/ecl_utils.h:30: multiple definition of `SSS_topics'
    build/Debug/GNU-Linux-x86/main.o:/.../QtGuiC2/../ECL/includes/ecl_utils.h:30: first defined here@

    Defined again at "ecl_utils.h", line 30. First definition in the very same file, at the very same line ;-)

    Looks like the same .h file is included multiple times, thus the warning about multiple definitions!

    This can easily happen if you include A.h and B.h in your source code file, but the file B.h also includes A.h. Or file B.h includes some other header file that then includes A.h (again). There are many ways this mess can happen.

    Usually this problem is avoided/resolved by guarding all header files like this:
    @foobar.h

    #ifndef FOOBAR_H_INCLUDED
    #define FOOBAR_H_INCLUDED

    /* Actual declarations here */

    #endif //FOOBAR_H_INCLUDED@

    So if it will be included a second (or third (or fourth)) time, it won't do any harm :)

    If the .h files of the libraries you are using have not been "guarded" like that, you have to fix that yourself (or ask the library author to fix it). Either that or you have to carefully check "who includes whom" and try to avoid multiple includes of the same .h file by re-organizing your #include commands...



  • My libraries have already the #ifndef ... #endif.
    This error for example:

    @
    /home/tommaso/Code/QtGuiC2/../ECL/includes/ecl_utils.h:30: multiple definition of `SSS_topics'
    build/Debug/GNU-Linux-x86/main.o:/home/tommaso/Code/QtGuiC2/../ECL/includes/ecl_utils.h:30: first defined here
    @

    It indicates that at line 30 SSS_topics is defined, but there isn't any definition of this variable...



  • I've solved my problem by splitting the definitions of a .h file to .cpp + .h files.
    The main problem was that I've a declaration of a map into a .h file (SSS_topics and the others).
    Since I moved the definition into the .cpp file, my problems seems to be over.
    Thank you!



  • Thanks all for your replies...!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.