Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33

Thread: Signal can't be emitted !

  1. #21
    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: Signal can't be emitted !

    i tried to call the signal after the connection, nothing happens.
    Ok, but if you "emit" a signal in constructor, which in fact simply calls "close" on a "newborn" widget, and then call show() on it again (main.cpp:8), it may look like nothing happened. Connect this signal to custom slot and qDebug() << something in that slot or set a breakpoint.

  2. #22
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal can't be emitted !

    I did connect to a custom slot and that has the same consequence, that's why I did a predefined slot.

    Can you please compile this in your pc and troubleshoot for me ?

    It would be better to know the issue.

  3. #23
    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: Signal can't be emitted !

    It is not possible without the .ui file.

  4. #24
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal can't be emitted !

    you can simply create a new project and copy these codes...

  5. #25
    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: Signal can't be emitted !

    Sorry but I'm using command line + notepad, it does not have a "new project" option. Maybe someone else will be able to help you.

  6. #26
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal can't be emitted !

    Ok, this is the mainwindow.ui

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>MainWindow</class>
    4. <widget class="QMainWindow" name="MainWindow">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>400</width>
    10. <height>300</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>MainWindow</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget"/>
    17. <widget class="QMenuBar" name="menuBar">
    18. <property name="geometry">
    19. <rect>
    20. <x>0</x>
    21. <y>0</y>
    22. <width>400</width>
    23. <height>21</height>
    24. </rect>
    25. </property>
    26. </widget>
    27. <widget class="QToolBar" name="mainToolBar">
    28. <attribute name="toolBarArea">
    29. <enum>TopToolBarArea</enum>
    30. </attribute>
    31. <attribute name="toolBarBreak">
    32. <bool>false</bool>
    33. </attribute>
    34. </widget>
    35. <widget class="QStatusBar" name="statusBar"/>
    36. </widget>
    37. <layoutdefault spacing="6" margin="11"/>
    38. <resources/>
    39. <connections/>
    40. </ui>
    To copy to clipboard, switch view to plain text mode 

  7. #27
    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: Signal can't be emitted !

    There is no problem with this code, if you emit the signal after making the connection, everything works as expected.
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. void callSignal();
    17. ~MainWindow();
    18.  
    19. private slots:
    20. void test();
    21.  
    22. signals:
    23. void _connected(int);
    24.  
    25.  
    26. private:
    27. Ui::MainWindow *ui;
    28. };
    29.  
    30. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QtGui>
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10.  
    11. bool c = connect(this,SIGNAL(_connected(int)), this, SLOT(test()));
    12. callSignal();
    13. QMessageBox::information(0, "Connect()", QString::number(c)); // shows c = 1 "true"
    14. }
    15.  
    16. void MainWindow::callSignal()
    17. {
    18. emit _connected(1);
    19. }
    20.  
    21. void MainWindow::test(){
    22. QMessageBox::information(0, "slot", "test");
    23. }
    24.  
    25. MainWindow::~MainWindow()
    26. {
    27. delete ui;
    28. }
    To copy to clipboard, switch view to plain text mode 

  8. #28
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal can't be emitted !

    You are calling show() after the signal has called close().

    Does "nothing happens" mean that the window is shown or that it is not?

    I would expect it to be shown, that is the last thing it is told to do.

    Cheers,
    _

  9. #29
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal can't be emitted !

    it is shown.

    and i used slots like maximizing the window ...etc but none is called.

  10. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal can't be emitted !

    Quote Originally Posted by Vladimir_ View Post
    it is shown.

    and i used slots like maximizing the window ...etc but none is called.
    With emitting the signal before or after the connect() statement?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #31
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal can't be emitted !

    emitting before the connect() statement. I corrected thhe source code ..

    i didn't expect to be stuck like this in signals and slots


    Added after 50 minutes:


    Guys, please compile it on your machines and tell me what happens ... maybe it's just from my compiler
    Last edited by Vladimir_; 27th September 2014 at 17:38.

  12. #32
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb Re: Signal can't be emitted !

    Okay, now it works.

    i made the connect() before the emit statement, then corrected the signal.

    thanks

  13. #33
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal can't be emitted !

    Quote Originally Posted by Vladimir_ View Post
    emitting before the connect() statement. I corrected thhe source code ..

    i didn't expect to be stuck like this in signals and slots


    Added after 50 minutes:


    Guys, please compile it on your machines and tell me what happens ... maybe it's just from my compiler
    If you emit a signal before making a connection, then obviously this signal emission will not be affected by the connection. C++ is an imperative language, order of statements matters.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Signal isn't emitted from socket
    By 8Observer8 in forum Newbie
    Replies: 3
    Last Post: 14th August 2013, 14:33
  2. loadFinished() signal not emitted
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 27th June 2013, 13:21
  3. QTcpSocket error signal emitted twice
    By CactusPie in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2013, 16:54
  4. signal emitted when I zoom
    By mastupristi in forum Qwt
    Replies: 1
    Last Post: 8th July 2009, 18:02
  5. Signal emitted more than once?
    By dbrmik in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2009, 13:44

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.