Originally Posted by
Cyrebo
Well actually, I can use functions in the main.cpp, I just need to know how to use them in mainwindow class please.
if you create a mew qt gui file it should do that for you automatically other wise you can do it manually->
use a header like this:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
private slots:
void functionSlot();
private:
void function();
//QWidgetType *QWidgetName.....
//ex:
};
#endif
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
private slots:
void functionSlot();
private:
void function();
//QWidgetType *QWidgetName.....
//ex:
QPushButton *pushButton;
};
#endif
To copy to clipboard, switch view to plain text mode
then on the mainWindow cpp file
#include <QtGui>
#include "mainwindow.h"
MainWindow::MainWindow(){
pushButton = newQPushButton;
function();
}
void MainWindow::function(){
pusButton->setText("Button");
//do something
}
#include <QtGui>
#include "mainwindow.h"
MainWindow::MainWindow(){
pushButton = newQPushButton;
function();
}
void MainWindow::function(){
pusButton->setText("Button");
//do something
}
To copy to clipboard, switch view to plain text mode
and on the main.cpp file
#include <QtGui/QApplication>
#inlucde "mainwindow.h"
int main(int argc, char *argv[]){
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#inlucde "mainwindow.h"
int main(int argc, char *argv[]){
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks