Results 1 to 6 of 6

Thread: Program crashes when connecting custom signal.

  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Program crashes when connecting custom signal.

    I have a mainwindow with a textedit widget.
    I would like my mainwindow to have an instance of a custom class, called "scene" that has signals and slots connected to ui items, like my textedit widget.

    I create my scene as follows:

    scene.h
    Qt Code:
    1. class scene : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. scene();
    7.  
    8. signals:
    9. void setImName(const QString&);
    10. };
    To copy to clipboard, switch view to plain text mode 

    scene.cpp
    Qt Code:
    1. #include "scene.h"
    2.  
    3. scene::scene() : QObject()
    4. {
    5. emit setImName( tr("hello") );
    6. }
    To copy to clipboard, switch view to plain text mode 

    In my mainwindow code, I declare a scene called "myScene" and attempt to connect it to the slot for my textedit widget. This compiles without error but results in a memory access related crash when I run my program. Commenting the "connect" line allows my program to run (but of course not behave as desired).
    Qt Code:
    1. connect(myScene, SIGNAL(setImName(const QString&)), ui->textEdit1, SLOT(setText(QString)));
    To copy to clipboard, switch view to plain text mode 

    Any ideas what I am doing wrong?
    I would appreciate any example where someone has created their own QObject with signals and slots that connect to ui widgets...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Program crashes when connecting custom signal.

    I guess the problem is the order of your statements. Can you show us the constructor of your main window.

  3. #3
    Join Date
    Jul 2009
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes when connecting custom signal.

    That was it!

    I was declaring my scene after the connect statement.

    Thanks.

  4. #4
    Join Date
    Jul 2007
    Location
    Noida
    Posts
    46
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes when connecting custom signal.

    Hi

    I think there is problem of connect statement..
    1.connect(myScene, SIGNAL(setImName(const QString&)), ui->textEdit1, SLOT(setText(QString)));

    It should be like this..
    1.connect(myScene, SIGNAL(setImName(const QString&)), ui->textEdit1, SLOT(setText(const QString&)));
    I hope it will work.
    Ashish Kumar Saryar

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Program crashes when connecting custom signal.

    Quote Originally Posted by ashishsaryar View Post
    I hope it will work.
    As hersheyzombie already said, the order was the problem and it doesn't make any difference if your write
    Qt Code:
    1. SLOT(setText(QString))
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. SLOT(setText(const QString&))
    To copy to clipboard, switch view to plain text mode 
    .

  6. #6
    Join Date
    Jul 2007
    Location
    Noida
    Posts
    46
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes when connecting custom signal.

    May be crash will happen by ui->textedit...

    Just check ui has got memory or not.
    Ashish Kumar Saryar

Similar Threads

  1. Program crashes on creating new dialog
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 11:52
  2. Connecting signal to custom slot?
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 30th April 2009, 09:28
  3. program crashes (QtTestRunner)
    By fmariusd in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2008, 09:27
  4. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 20:09
  5. Reading from TCP Socket crashes program
    By OnionRingOfDoom in forum Qt Programming
    Replies: 26
    Last Post: 27th January 2006, 19:32

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.