Hi.
I need a help.
I have a variable int bit2, which is a mainwindow.h.
In main.cpp I calculate her value, and I want to send this value to mainwindow.cpp. Is this possible?
I include part of the cod:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
static int bit2;
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
int flag;
void zapisz(int wartosc);
private slots:
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
static int bit2;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
int flag;
void zapisz(int wartosc);
private slots:
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
main.cpp
int main(int argc, char **argv)
{
MainWindow w;
w.show();
...
...
w.zapisz(51);
int main(int argc, char **argv)
{
QApplication a(argc, argv);
MainWindow w;
w.show();
...
...
w.zapisz(51);
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPixmap pix
("/home/bananapi/wizu-build-desktop-Qt_4_8_2__System__Release/new_grn.bmp");
QPixmap pix2
("/home/bananapi/wizu-build-desktop-Qt_4_8_2__System__Release/new_red.bmp");
ui->label->setPixmap(pix);
ui->label_2->setPixmap(pix);
ui->label_3->setPixmap(pix);
ui->label_4->setPixmap(pix);
flag=0;
int bit;
bit=bit2;//TU JEST BLAD ;/
...
...
void MainWindow::zapisz(int wartosc)
{
bit2=wartosc;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPixmap pix("/home/bananapi/wizu-build-desktop-Qt_4_8_2__System__Release/new_grn.bmp");
QPixmap pix2("/home/bananapi/wizu-build-desktop-Qt_4_8_2__System__Release/new_red.bmp");
ui->label->setPixmap(pix);
ui->label_2->setPixmap(pix);
ui->label_3->setPixmap(pix);
ui->label_4->setPixmap(pix);
flag=0;
int bit;
bit=bit2;//TU JEST BLAD ;/
...
...
void MainWindow::zapisz(int wartosc)
{
bit2=wartosc;
}
To copy to clipboard, switch view to plain text mode
When I write in mainwindow.cpp ¨bit=51¨ (value which I want calculate in main.cpp) programm is working. In my opinion bit2 in main.cpp and bit2 in mainwindow.cpp is different variable. Can someone help? There is any way to send value from main.cpp to mainwindow.cpp?
Bookmarks