Re: Signal can't be emitted !
Quote:
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.
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.
Re: Signal can't be emitted !
It is not possible without the .ui file.
Re: Signal can't be emitted !
you can simply create a new project and copy these codes...
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.
Re: Signal can't be emitted !
Ok, this is the mainwindow.ui
Code:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
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.
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
void callSignal();
~MainWindow();
private slots:
void test();
signals:
void _connected(int);
private:
Ui::MainWindow *ui;
};
#endif
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
bool c = connect(this,SIGNAL(_connected(int)), this, SLOT(test()));
callSignal();
}
void MainWindow::callSignal()
{
emit _connected(1);
}
void MainWindow::test(){
}
MainWindow::~MainWindow()
{
delete ui;
}
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,
_
Re: Signal can't be emitted !
it is shown.
and i used slots like maximizing the window ...etc but none is called.
Re: Signal can't be emitted !
Quote:
Originally Posted by
Vladimir_
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?
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
Re: Signal can't be emitted !
Okay, now it works.
i made the connect() before the emit statement, then corrected the signal.
thanks
Re: Signal can't be emitted !
Quote:
Originally Posted by
Vladimir_
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.