Results 1 to 3 of 3

Thread: Problems launching a window when I press a button

  1. #1
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Problems launching a window when I press a button

    Hello everybody:

    I’m learning to code with C++ and QT and I’m having a problem that I can’t solve. I’ll try to explain myself clearly.

    I’m working with an example I found, it creates a simple window with several buttons that work ok. I made another window and I want it to appear when button “hacer algo” is clicked.

    The code compiles ok and it executes opening the principal window, but I get the following errors in a cmd window:
    “Object::connect: No such slot miApVentana::doSomething(argc, argv) in ..\ApVentana\ApVentana.cpp
    Object::connect: (sender name: ‘boton_haceralgo’)
    Object::connect: (receiver name: ‘ApVentana’)”

    It works correctly except that button.

    I attach the code, sorry some names and comments are in Spanish but it’s quite clear. I’m having problems uploading the code. I’ll paste it below. I work with Qt SDK 2010.04 on Windows XP.

    Thank you very much for your help.

    Regards
    ----------------------------------------------------
    ApVentana.pro
    CONFIG = qt
    HEADERS = ApVentana.h ventana2.h
    SOURCES = ApVentana.cpp ventana2.cpp main.cpp
    FORMS = ApVentana.ui ventana2.ui
    # install
    target.path = ApVentana
    sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
    sources.path = .
    INSTALLS += target sources
    --------------------------------------------Apventana.h

    #ifndef APVENTANA_H
    #define APVENTANA_H
    #include "ui_ApVentana.h"
    class miApVentana : public QWidget, private Ui::ApVentana
    {
    Q_OBJECT
    //Constructor
    public:
    miApVentana(QWidget *parent = 0);
    //Son los métodos de cada uno de los botones
    public slots:
    void getPath();
    int doSomething(int argc, char *argv[]);
    void clear();
    void about();
    };
    #endif // APVENTANA_H

    ----------------------------------------Ventana2.h
    #ifndef VENTANA2_H
    #define VENTANA2_H
    #include "ui_ventana2.h"
    class ventanina : public QWidget, private Ui::ventana2
    {
    Q_OBJECT
    public:
    ventanina(QWidget *parent = 0);
    public slots:
    void Volver();
    };
    #endif // VENTANA2_H

    -------------------------------------ApVentana.cpp
    #include <QtGui>
    #include <QApplication>
    #include "ApVentana.h"
    #include "ventana2.h"
    // if we include <QtGui> there is no need to include every class used: <QString>, <QFileDialog>,...
    miApVentana::miApVentana(QWidget *parent)
    {
    setupUi(this); // this sets up GUI
    // signals/slots mechanism in action
    connect( boton_explorar, SIGNAL( clicked() ), this, SLOT( getPath() ) );
    connect( boton_limpiar, SIGNAL( clicked() ), this, SLOT( clear() ) );
    connect( boton_informacion, SIGNAL( clicked() ), this, SLOT( about() ) );
    connect( boton_haceralgo, SIGNAL(clicked()), this, SLOT ( doSomething(argc, argv)));
    }
    //Función del botón explorar
    void miApVentana::getPath()
    {
    QString path;
    path = QFileDialog::getOpenFileName(
    this,
    "Escoge un archivo para abrir",
    QString::null,
    QString::null);
    texto_explorar->setText( path );
    }
    //Función del botón Limpiar
    void miApVentana::clear()
    {
    texto_editar->clear();
    }
    //Función del botón Información
    void miApVentana::about()
    {
    QMessageBox::about(this,"About myQtApp",
    "This app was coded for educational purposes.\n"
    "Number 1 is: " + QString::number(spinBox1->value()) + "\n\n"
    "Bye.\n");
    }
    int miApVentana::doSomething(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    ventanina *dialog = new ventanina;
    dialog->show();
    return app.exec();
    }

    ----------------------------------Ventana2.cpp
    #include <QtGui>
    #include "ventana2.h"
    // if we include <QtGui> there is no need to include every class used: <QString>, <QFileDialog>,...
    ventanina::ventanina(QWidget *parent)
    {
    setupUi(this); // this sets up GUI
    // signals/slots mechanism in action
    connect( boton_volver, SIGNAL( clicked() ), this, SLOT( Volver() ) );
    }
    void ventanina::Volver()
    {
    textEdit->clear();
    }

    --------------------------------Main.cpp
    #include <QApplication>
    #include "ApVentana.h"
    #include "ventana2.h"
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    miApVentana *dialog = new miApVentana;
    dialog->show();
    return app.exec();
    }

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems launching a window when I press a button

    change this
    Qt Code:
    1. onnect( boton_haceralgo, SIGNAL(clicked()), this, SLOT ( doSomething(argc, argv)));
    To copy to clipboard, switch view to plain text mode 

    to

    Qt Code:
    1. onnect( boton_haceralgo, SIGNAL(clicked()), this, SLOT ( doSomething()));
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. nt miApVentana::doSomething()
    2. {
    3. //QApplication app(argc, argv);
    4. ventanina *dialog = new ventanina;
    5. dialog->show();
    6. //return app.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems launching a window when I press a button

    Thanks!!!!!!!!!!!!!!!!

    That worked perfectly.

    Thanks again MrDeath

Similar Threads

  1. Problems launching a windows exe from Qt (using QProcess)
    By smacchia in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2012, 11:05
  2. Replies: 0
    Last Post: 10th September 2010, 14:23
  3. Replies: 6
    Last Post: 21st August 2010, 22:09
  4. Replies: 1
    Last Post: 17th May 2010, 17:15
  5. Replies: 2
    Last Post: 10th November 2009, 07:17

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.