I hope that you help me
-
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 :
mainwindow.h
@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();public slots:
void openHTML(); //ADD THIS LINEprivate:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
@
mainwindow.cpp
@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qdesktopservices.h>
#include <QUrl>
#include <QObject>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);//ADD THIS LINE connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(openHTML())); //or //connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(openHTML()));}
MainWindow::~MainWindow()
{
delete ui;
}//ADD THIS SLOTvoid MainWindow::openHTML()
{
QDesktopServices::openUrl(QUrl("file:///C:/QtProject.htm"));
}
@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
-
@
void MainWindow::MainWindow(QWidget * parent):
QMainWindow(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)
{
QDesktopServices::openUrl(QUrl("file:///C:/QtProject.htm"));
}
@
In your class definition:
@
public slots:
void OpenURLRequest(void);
@ -
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.htmlHope 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
-
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