Results 1 to 12 of 12

Thread: Error message in QThread

  1. #1
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Error message in QThread

    Hi

    I've a separate thread running.
    In that thread, I like to let the user know there is some error.
    However, the usual Qmessagebox is not working while running
    a thread. Is there any other way to prompt a pop up or
    some messages while within a thread?

    Thanks for any help. I'm stuck on this for sometime.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Error message in QThread

    Move the QMessageBox to the Main thread, and send a signal to the QMessageBox from the separate tread.

    This is how it is supposed to be used, all GUI components should be in main thread only.

  3. #3
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Re: Error message in QThread

    Sorry for my ignorant. But how do you send a signal from a separate thread?
    I can understand we should only use the Qmessagebox in the main thread. But
    cant figure out how do I send a signal from the thread?

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Error message in QThread

    Refer this example to send signals to Main (GUI) thread from QThread
    http://www.qtcentre.org/wiki/index.p...I_from_QThread

  5. #5
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Re: Error message in QThread

    Thanks.
    I followed the example but gotten this error during linking.
    LNK2019:unresolved external symbol"protected: void __thiscall mythread:valuceChanged(int)"

    What I dont get is, this valueChanged is the standard function for signals.
    So, do I have to define it again in my own function?
    And the example didnt show that we need to define this valueChanged function either.

    Any help?

  6. #6
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Error message in QThread

    Please take a look again at the example in the link that Santosh has provided. There is "Source Files" section, where you have this simple mechanism of connection signals to slots implemented. If you look more closely you will see that valueChanged is a custom signal of MyThread class. Now you have to define your own signal in your own thread.

  7. #7
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Re: Error message in QThread

    Thanks.
    Sorry, but I've been looking at the files and also downloaded them and view them again and again.
    There is no indication of how do you and where did it define the valueChanged.
    I read that there is the
    1. signals:
    void valueChanged(int);
    2. emit valueChanged(i);

    But there is nothing on how do you define this valueChanged function. Do we need the metaobject to define it?
    If I compile this, I'll get the error - LNK2019:unresolved external symbol"protected: void __thiscall mythread:valuceChanged(int)".
    I'm still confused...

  8. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Error message in QThread

    valueChanged is a signal, and you don't provide implementation of signals, moc does.
    Be sure to do a clean build (make clean, qmake, make). Check if moc code is generated for your class (dont forget Q_OBJECT macro).

  9. #9
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Re: Error message in QThread

    Hi.

    I did a clean and rebuild. I also make sure I've Q_Object macro in mythread.
    Now I got the following errors. Before I added Q_Object, I've only the LNK2019 error.
    Also, can you confirm that even for custom signals like the earlier author Rachol replied,
    that I still do not need to provide implementation of the valueChanged function?
    If so, how do I resolve these metaobject error below?

    Please help. I'm losing my hair over this and cant move on.


    Qt Code:
    1. mythread.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall mythread::metaObject(void)const " (?metaObject@mythread@@UBEPBUQMetaObject@@XZ)
    2. mythread.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __thiscall mythread::qt_metacast(char const *)" (?qt_metacast@mythread@@UAEPAXPBD@Z)
    3. mythread.obj:-1: error: LNK2001: unresolved external symbol "public: virtual int __thiscall mythread::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@mythread@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
    4. mythread.obj:-1: error: LNK2019: unresolved external symbol "protected: void __thiscall mythread::valueChanged(int)" (?valueChanged@mythread@@IAEXH@Z) referenced in function "public: void __thiscall mythread::init(void)" (?init@mythread@@QAEXXZ)
    5. mythread.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const mythread::staticMetaObject" (?staticMetaObject@mythread@@2UQMetaObject@@B)
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Error message in QThread

    You do not provide implementation of any signals, because moc will do that. You need to implement slots if you have any.
    This looks like moc code is not compiled, how do you build your project ? If you have a .pro file, post it here. Show the header too, maybe you have some obvious errors, typos etc.

  11. #11
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Re: Error message in QThread

    Hi.
    Below is my .pro file.
    I'm using QT creator as my IDE.
    Yes. I've implemented my slots.
    I think you're right. I'm missing the moc codes.
    So, how do I ask QT creator to build moc codes?

    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2011-04-25T10:51:02
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. TARGET = mylittleProgram
    10. TEMPLATE = app
    11.  
    12.  
    13. SOURCES += main.cpp\
    14. mainwindow.cpp \
    15. mylittleheader.cpp \
    16. mylittlerender.cpp \
    17. mylittlereaddata.cpp \
    18. mythread.cpp
    19.  
    20. HEADERS += mainwindow.h \
    21. mylittleheader.h \
    22. mylittlerender.h \
    23. mylittlereaddata.h \
    24. mythread.h
    25.  
    26.  
    27. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Error message in QThread

    It should do it automatically.
    .pro file looks ok, so I'd start by running qmake and check if Makefiles contains correct moc build targets.

Similar Threads

  1. Getting an error for QString::arg instead of message
    By akiross in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2011, 10:57
  2. Message editor already in use error
    By Ismb in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 17th February 2011, 14:22
  3. error message
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2009, 14:08
  4. Showing a error message
    By srohit24 in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2009, 07:05
  5. getting the error message when trying to run the application in QT
    By pallavi Boyapat in forum Qt Programming
    Replies: 49
    Last Post: 31st October 2008, 12:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.