Results 1 to 2 of 2

Thread: deleting QListItemWidget crashed which was triggered by another thread

  1. #1
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    3

    Default deleting QListItemWidget crashed which was triggered by another thread

    I created QMainWidget which contains a QListWidget to show log information coming from a socket thread which processed network business. showing log info slots (addLogInfo(const QString &log)) was triggered by a signals in that socket thread . a log item will be created and added to QListWidget every 20 milliseconds.

    the signal and the slot was connected in the socket thread's run function with Qt:irectConnection:

    connect(this, SIGNAL(addLogInfo(const Log::LogLevel &, const QString &)), parent, SLOT(addLogInfo(const Log::LogLevel &, const QString &)), Qt:irectConnection);

    here, "this" is pointed the socket thread object, "parent" is a QMainWidget pointer which pointed to GUI which contained the QListWidget.

    in such partern with Qt:irectConnection, I think that the addLogInfo slot was executed in the socket thread(am I right?). In fact, What I want really is that the slot was executed by QMainWidget thread itself which can be done through Qt::QueuedConnection. But when I set connect function with Qt::QueuedConnection, it will complain:
    "QObject::connect: Cannot queue arguments of type 'Log::LogLevel'
    (Make sure 'Log::LogLevel' is registered using qRegisterMetaType())

    But I don't know how to register my user-defined type Log::LogLevel, such statement:
    qRegisterMetaType<Log::LogLevel>("LogLevel") won't work. Log is:
    class Log
    {
    private:
    Log();
    ~Log();
    public:
    enum LogLevel {Debug=0, Info=1, Warning=2, Error=3, Fatal=4};
    };

    when QListWidgetItem number in QListWidget is more than a threshold (such as 50), QMainWidget will delete the first QListWidgetItem in QListWidget through the statement "delete lsgLogInfo->item(0)" located in the slot.

    After deleting item several times, the program will crash with following gdb info:
    ASSERT failure in QVector<T>:perator[]: "index out of range", file ../../include/QtCore/../../src/corelib/tools/qvector.h, line 324

    In fact , I inserted a statement "printf("count=%d\n", ui.lstLogInfo->count());" which printed the count is the threshold plus one. So , the deleted index equal to 0 will not be out of range. But the crash really happened.

    anybody can help me?
    any help will be appreciated!
    thx!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: deleting QListItemWidget crashed which was triggered by another thread

    Please do not cross-post.
    J-P Nurmi

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  2. Replies: 10
    Last Post: 20th March 2007, 22:19

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.