Originally Posted by
wysota
Either use a dot (".") instead of an arrow ("->") or redesign so that you an use signals and slots without having a reference to the main window object.
No luck
qt4test_data.cpp: In member function ‘void qt4testData::init()’:
qt4test_data.cpp:32: error: ‘class Ui::MainWindow’ has no member named ‘changeVar’
qt4test_data.cpp: In member function ‘void qt4testData::init()’:
qt4test_data.cpp:32: error: ‘class Ui::MainWindow’ has no member named ‘changeVar’
To copy to clipboard, switch view to plain text mode
I'm becoming crazy...
I tried first the solution you suggest... but was too difficult for me.
I post now some sample code:
"main_window.cpp":
#include "main_window.h"
#include "qt4test_data.h"
{
ui.setupUi (this);
QObject::connect(ui.
horizontalSlider,
SIGNAL(valueChanged
(int)), ui.
spinBox,
SLOT(setValue
(int)));
connect (ui.pushButton2, SIGNAL(pressed()),
this, SLOT(slotPush2Pressed()));
init ();
}
void qt4testMainWindow::init ()
{
QString stringToSend
= "TestString";
int integerToSend = 10;
qt4testData *myqt4testData = new qt4testData ( stringToSend , integerToSend , ui );
statusBar()->showMessage (tr("Starting..."));
}
void qt4testMainWindow::slotPush2Pressed ()
{
qDebug ("\nqt4testMainWindow::slotPush2Pressed\n");
}
void qt4testMainWindow::changeVar ( int newValue )
{
qDebug ("\nqt4testMainWindow::changeVar - newValue: %d\n" , newValue );
ui.spinBox->setValue ( newValue );
}
#include "main_window.h"
#include "qt4test_data.h"
qt4testMainWindow::qt4testMainWindow (QWidget *parent) : QMainWindow (parent)
{
ui.setupUi (this);
QObject::connect(ui.horizontalSlider, SIGNAL(valueChanged(int)), ui.spinBox, SLOT(setValue(int)));
connect (ui.pushButton2, SIGNAL(pressed()),
this, SLOT(slotPush2Pressed()));
init ();
}
void qt4testMainWindow::init ()
{
QString stringToSend = "TestString";
int integerToSend = 10;
qt4testData *myqt4testData = new qt4testData ( stringToSend , integerToSend , ui );
statusBar()->showMessage (tr("Starting..."));
}
void qt4testMainWindow::slotPush2Pressed ()
{
qDebug ("\nqt4testMainWindow::slotPush2Pressed\n");
}
void qt4testMainWindow::changeVar ( int newValue )
{
qDebug ("\nqt4testMainWindow::changeVar - newValue: %d\n" , newValue );
ui.spinBox->setValue ( newValue );
}
To copy to clipboard, switch view to plain text mode
"main_window.h":
#include "ui_main_window.h"
#include <QtDebug>
class qt4testData;
{
Q_OBJECT
public:
qt4testMainWindow
( QWidget *parent
= 0 );
void changeVar ( int newValue );
signals:
private:
Ui::MainWindow ui;
void init ();
public slots:
void slotPush2Pressed ();
private slots:
};
#include "ui_main_window.h"
#include <QtDebug>
class qt4testData;
class qt4testMainWindow : public QMainWindow
{
Q_OBJECT
public:
qt4testMainWindow ( QWidget *parent = 0 );
void changeVar ( int newValue );
signals:
private:
Ui::MainWindow ui;
void init ();
public slots:
void slotPush2Pressed ();
private slots:
};
To copy to clipboard, switch view to plain text mode
"qt4test_data.cpp":
#include "qt4test_data.h"
qt4testData::qt4testData (QString& testString, int testNumber, Ui::MainWindow& main_ui_temp)
{
qDebug ("\nqt4testData::qt4testData -> constructor");
mytestString = testString;
mytestNumber = testNumber;
qDebug () << "\nqt4testData::qt4testData -> 'mytestString' variable: " << mytestString << "\n";
qDebug () << "\nqt4testData::qt4testData -> 'mytestNumber' variable: " << mytestNumber << "\n";
main_ui = main_ui_temp;
init ();
}
void qt4testData::init ()
{
qDebug ("\nqt4testData::init -> init");
main_ui.spinBox->setValue (80);
main_ui.changeVar ( 20 );
}
#include "qt4test_data.h"
qt4testData::qt4testData (QString& testString, int testNumber, Ui::MainWindow& main_ui_temp)
{
qDebug ("\nqt4testData::qt4testData -> constructor");
mytestString = testString;
mytestNumber = testNumber;
qDebug () << "\nqt4testData::qt4testData -> 'mytestString' variable: " << mytestString << "\n";
qDebug () << "\nqt4testData::qt4testData -> 'mytestNumber' variable: " << mytestNumber << "\n";
main_ui = main_ui_temp;
init ();
}
void qt4testData::init ()
{
qDebug ("\nqt4testData::init -> init");
main_ui.spinBox->setValue (80);
main_ui.changeVar ( 20 );
}
To copy to clipboard, switch view to plain text mode
"qt4test_data.h":
#include <QtDebug>
#include "ui_main_window.h"
{
Q_OBJECT
public:
qt4testData (QString& testString, int testNumber, Ui::MainWindow& main_ui_temp);
private:
void init ();
Ui::MainWindow main_ui;
int mytestNumber;
};
#include <QtDebug>
#include "ui_main_window.h"
class qt4testData: public QObject
{
Q_OBJECT
public:
qt4testData (QString& testString, int testNumber, Ui::MainWindow& main_ui_temp);
private:
void init ();
Ui::MainWindow main_ui;
QString mytestString;
int mytestNumber;
};
To copy to clipboard, switch view to plain text mode
Or can you tell me where to find documentation or an example to study?
Thanks,
the_bis
Bookmarks