I hope that you help me

  • hello
    can any one help me please
    this is my code iwant to create a button that when it clicked an html file open



    #include <QTwidjets>
    int main(int argc, char *argv[])
    QApplication app(argc, argv);

    QPushButton bouton;
    QString link ="C:/Users/kouki/Desktop/versement.html";


    return app.exec();
    and this is the error
    C:\Users\kouki\qtprojects\tesehtml\main.cpp:19: erreur : C2665: 'QObject::connect'ÿ: aucune des 3 surcharges n'a pu convertir tous les types d'arguments
    c:\qt\qt5.2.1\5.2.1\msvc2012_64_opengl\include\qtcore\qobject.h(198): peut ˆtre 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)'
    c:\qt\qt5.2.1\5.2.1\msvc2012_64_opengl\include\qtcore\qobject.h(201): ou 'QMetaObject::Connection QObject::connect(const QObject *,const QMetaMethod &,const QObject *,const QMetaMethod &,Qt::ConnectionType)'
    c:\qt\qt5.2.1\5.2.1\msvc2012_64_opengl\include\qtcore\qobject.h(205): ou 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const'
    lors de la tentative de mise en correspondance de la liste des arguments '(QPushButton *, const char *, QString *, const char *)'
    thank you in advance

  • Hi,
    My French is terrible, so no idea what your error codes tell me, besides your made a signal/slot error.
    The Signal/slot connection you created is wrong.
    The openUrl is a static member function, not a slot!
    So in a class generate a slot, in that slot, call the static openUrl function.
    The second mistake in your signal/slot is that both signal and slots need to have the same arguments!
    Read this article please:
    "Signals explained":https://qt-project.org/doc/qt-5.0/qtcore/signalsandslots.html

  • Moderators

    Hi Yakine,

    I advice you to read/understand the following :"getting started guide" http://qt-project.org/doc/qt-5/gettingstartedqt.html

    I adapted it a little to your likings below.

    Try the following approach :
    make a new project using widgets and choose QMainwindow. (or QDialog, but then you get other names and stuff...)

    adapt the ui file and add a QPushButton to it using Qt Creator. Keep the default name for it : pushButton.

    then alter the following files :
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;

    class MainWindow : public QMainWindow

    explicit MainWindow(QWidget *parent = 0);

    public slots:
    void openHTML(); //ADD THIS LINE

    Ui::MainWindow *ui;

    #endif // MAINWINDOW_H
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <qdesktopservices.h>
    #include <QUrl>
    #include <QObject>

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    connect(ui->pushButton, SIGNAL(clicked()), this,  SLOT(openHTML()));
    //connect(ui->pushButton, SIGNAL(clicked()),  this, SLOT(openHTML()));


    delete ui;


    void MainWindow::openHTML()

    Feel free to ask here if you have any doubts.

  • koukou

    thank you both but Eddy i want that you knew that i have created an empty project am programing evry thing with qt creator i don't use the qt design i tryed what you suggest and it work's but it's not what i need if you can help please and sorry about my English

  • if you can tell me what slot i supposed to use ?

  • @
    void MainWindow::MainWindow(QWidget * parent):
    m_PushButton * = new QPushButton(this);
    m_PushButton.setText("Start URL");
    connect (m_PushButton, SIGNAL(clicked()),
    this, SLOT(OpenURLRequest()));

    // --> THIS IS YOUR SLOT!!!
    void MainWindow::OpenURLRequest(void)
    In your class definition:
    public slots:
    void OpenURLRequest(void);

  • Moderators

    Hi Yakine,

    I advice you to read the book :
    "C++ GUI Programming with Qt 4"
    If you google you might find the first version which is free.

    chapter 2 explains in detail what you need (using only code and no ui file)

    Basically you make a new class, put your button in it. Put it in a QLayout. Add a slot and connect to that slot. I already gave you 2 connect statements.

    here is another example :
    "Basic Layout Example":http://qt-project.org/doc/qt-4.8/layouts-basiclayouts.html

    Hope this helps

  • am terrible i knew but sorry look i don't use poo i don't crate classes
    all that i do it's crating an empty project with contain a main.cpp
    in this main i creat my window
    @QWidget window ;@

    then i crate a qpushbutton like this

    @QPushbutton button("open",&window);@

    and when user clicked on this button an html file wich i created and i saved on my desktop open but how can i connect btween the button that i created and the html file

  • Moderators

    Your "window" doesn't have a slot that calls openUrl.

    That's why you have to make a derived class and define a custom slot yourself, as we showed you.

    Please read the links we gave you, they will help you understand

  • thank you a lot Eddy am reading what you suggest and when i finished i will try to do it . thank you so much you are great person
    i have a little request if you have any suggest or any tuto that can help me to realise a managment application for a medical office with qt Creator thank you again

  • Moderators


    I can't help you with your new question. I suggest you start a new topic and be specific about what you want. Your question is too general.

  • ok thank's have a good day

Log in to reply

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