PDA

View Full Version : WIdget relationship with Main Window



Robobulls
23rd May 2013, 20:15
Hello all, I am fairly new to Qt so do not know all the ins and outs yet but I am attepting to create a simple matrix program with the results beign that when one parameter changes in the main window the widget is affected and shows the results. I have been reading online forums and all seem to say that interaction with Ui of the main window and the Ui of the widget is not allowed I also found another thread with a sample code on how to make it work (I will also post in bottom.) the code seemed to work but when attempting to compile several error messages came up


#include <QMainWindow>
#include "array.h"
#include "matrix.h"
//trying to get windows to recognize Matrix ui
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Ui::MainWindow *ui;//made ui public instead of private
Ui::Matrix*yw;//Here is the change I was recomended to add the widget class Ui to my main window



private:


protected:
void mousePressEvent(QMouseEvent * e);
private slots:
void on_radioButton_clicked(bool checked);
};

#endif // MAINWINDOW_H

Then in my Cpp file i added this line


void MainWindow::on_radioButton_clicked(bool checked)
{
yw->label->setText("on");//Also recommendation
}

here is the error I recieved after compilation

ui_mainwindow.h:39: error: 'Matrix' does not name a type//

When this did'nt work I made some changes to the Cpp again attempting to establish a parent child relationship with the widget and main window but I am not sure if I was succesful


ui(new Ui::MainWindow),matrix(new Ui::Matrix)//here is what I changed
{
ui->setupUi(this);
matrix->setupUi(this->ui->centralWidget);//Added this

I am at a bit of a dead end with how to approach this now hope someone can help

amleto
24th May 2013, 01:12
Qt is not something you can just use without good knowledge of c++. I suggest you do some reading + exercises on basic c++.

There is no need to make those pointers public.

You ask us to diagnose compiler error about Matrix, but don't even show us Matrix code...

All of what you have found/been recommended seems incorrect or you have misunderstood, to be honest.

Robobulls
5th June 2013, 18:00
Thanks for the reply I am doing research in QT and am doing exercises. What my question was asking and I am sorry if I was unclear is if it is possible to have a widget created inside of the main window be affected by the main window (when main window info changes it is reflected in the widget) and what is the best way to attempt this. Like you said a lot of the information I have found is incorrect or unrelated to my problem.

KaptainKarl
6th June 2013, 00:04
If you put a QPushButton on the MainWindow and put a QLabel on the MainWindow and then write a slot for the QPushButton that alters the text in the QLabel, have you not done something in the MainWindow that affected the QLabel widget?

Perhaps I am not understanding your question. Have you attempted the Application Example (http://qt-project.org/doc/qt-5.0/qtwidgets/mainwindows-application.html) in the Qt Reference documentation? ()

Karl

Robobulls
11th June 2013, 22:33
I have tried using the Qpushbutton but when I try to put the ui location for my widget the only recognized ui is the main windows