Object::connect: No such signal issue



  • Hi,
    I create new signals and slots and when i run my program i have this error, but check it and everthing looks ok.
    @
    Object::connect: No such signal MainWindow::hotovo(vector<string> data) in mainwindow.cpp:15
    Object::connect: (sender name: 'MainWindow')
    Object::connect: (receiver name: 'Dialog')@

    mainwindow.h
    @#include <QMainWindow>
    #include "dialog.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:

    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    std::vectorstd::string cestaTabulky;
    std::vectorstd::string jmenaTabulky;
    std::vectorstd::string data2;
    std::vector<int> pocty;
    protected slots:
    void naplnit_comboBox();
    signals:
    void hotovo(std::vectorstd::string data);
    private slots:
    void on_pridatBttn_clicked();
    void on_comboBox_currentIndexChanged(int index);

    private:
    Ui::MainWindow *ui;
    Dialog *pridani;

    };@

    mainwindow.cpp

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    pridani = new Dialog(this);
    connect(pridani,SIGNAL(created()),this,SLOT(naplnit_comboBox())); connect(this,SIGNAL(hotovo(vector<string>data)),pridani,SLOT(naplnit_comboBox2(vector<string> data) ) );

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_pridatBttn_clicked()
    {

    pridani->show();
    }

    void MainWindow::naplnit_comboBox()
    {

    emit hotovo(jmenaTabulky);
    

    }

    void MainWindow::on_comboBox_currentIndexChanged(int index)
    {
    QStandardItemModel model = qobject_cast<QStandardItemModel>(ui->tableView->model());
    int radek = 0;
    int sloupec = 7;

       int pocetRadku  = data2.size()/5;
       //if (index != 0) index-- ;
    

    ui->tableView->updatesEnabled();
    for (radek = 0; radek < pocetRadku;radek++)
    {

               QStandardItem *item =  model->item(radek,sloupec);
               QString data = item->accessibleText();
               if(jmenaTabulky[index].compare(data.toStdString()) == 0)
                   {
                       ui->tableView->setColumnHidden(radek,false);
                   }
                       else
                   {
                       ui->tableView->setColumnHidden(radek,true);
                   }
    
        }
    

    }

    @



  • Do you have any warnings from a compiler?

    From you code I don't see that you have
    @
    #include <vector>
    #include <string>
    //... etc
    @
    Is it included in "dialog.h"

    One more thing.
    Do you use vector from STL?
    You did not put std:: in front of vector and string in the signal declaration.
    But you did it few lines above.



  • [quote author="andreyc" date="1401297592"]Do you have any warnings from a compiler?

    From you code I don't see that you have
    @
    #include <vector>
    #include <string>
    //... etc
    @
    Is it included in "dialog.h"

    One more thing.
    Do you use vector from STL?
    You did not put std:: in front of vector and string in the signal declaration.
    But you did it few lines above.
    [/quote]
    yes, i it is. i correct namespace in hotovo and it havent effect on it.



  • Do you have the same error ?
    @
    Object::connect: No such signal MainWindow::hotovo(vector<string> data) in mainwindow.cpp:15
    @



  • [quote author="andreyc" date="1401298839"]Do you have the same error ?
    @
    Object::connect: No such signal MainWindow::hotovo(vector<string> data) in mainwindow.cpp:15
    @
    [/quote]

    yes



  • Yep, I see. Created a project and got the same result.
    Try to use "new connect":http://qt-project.org/wiki/New_Signal_Slot_Syntax#b61c3e32c4a7548eb2a0ea5a505fd51b
    @
    connect(this, &MainWindow::hotovo, pridani, &Dialog::naplnit_comboBox2);
    @



  • [quote author="andreyc" date="1401299367"]Yep, I see. Created a project and got the same result.
    Try to use "new connect":http://qt-project.org/wiki/New_Signal_Slot_Syntax#b61c3e32c4a7548eb2a0ea5a505fd51b
    @
    connect(this, &MainWindow::hotovo, pridani, &Dialog::naplnit_comboBox2);
    @[/quote]

    no it doesnt work i use Qt 4.8.1



  • As a workaround you may try to use QVector<QString>



  • Are you certain that the signature of the signal and slot match? I put together this example that has a signal and slot which use std::vector.

    @
    #include <QCoreApplication>
    #include <QMetaEnum>
    #include <QDebug>

    #include <cstdio>
    #include <vector>

    class Object : public QObject
    {
    Q_OBJECT
    public:
    Object() : QObject() {}

    public slots:
    void mySlot(std::vector<int> param)
    {
    qDebug() << "This is" << PRETTY_FUNCTION << "with" << param.front();
    }

    signals:
    void mySignal(std::vector<int> param);
    };

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    Object obj;
    const QMetaObject *meta = obj.metaObject();
    qDebug() << "walking meta-Object" <&lt; meta;
    for (int i = 0; i &lt; meta->methodCount(); i++) {
        QMetaMethod method = meta->method(i);
        qDebug() << "method:" << method.methodSignature().data();
    }
    obj.connect(&obj, SIGNAL(mySignal(std::vector<int>)), &obj, SLOT(mySlot(std::vector<int>)));
    std::vector<int> vec(1);
    vec[0] = 12345;
    emit obj.mySignal(vec);
    return 0;
    

    }

    #include "main.moc"
    @



  • Having taken a closer look at the code, I think the problem is the use of the SIGNAL macro, which specifies a parameter of "vector" instead of "std::vector".

    The old-style connect() is string driven, using the declaraction of the signal and slot, and the parameters to SIGNAL() and SLOT(). It doesn't know that vector is a std::vector if preceeded by using namespace std.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.