Results 1 to 5 of 5

Thread: WIdget relationship with Main Window

  1. #1
    Join Date
    May 2013
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default WIdget relationship with Main Window

    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
    Qt Code:
    1. #include <QMainWindow>
    2. #include "array.h"
    3. #include "matrix.h"
    4. //trying to get windows to recognize Matrix ui
    5. namespace Ui {
    6. class MainWindow;
    7. }
    8.  
    9. class MainWindow : public QMainWindow
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. explicit MainWindow(QWidget *parent = 0);
    15. ~MainWindow();
    16. Ui::MainWindow *ui;//made ui public instead of private
    17. Ui::Matrix*yw;//Here is the change I was recomended to add the widget class Ui to my main window
    18.  
    19.  
    20.  
    21. private:
    22.  
    23.  
    24. protected:
    25. void mousePressEvent(QMouseEvent * e);
    26. private slots:
    27. void on_radioButton_clicked(bool checked);
    28. };
    29.  
    30. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Then in my Cpp file i added this line
    Qt Code:
    1. void MainWindow::on_radioButton_clicked(bool checked)
    2. {
    3. yw->label->setText("on");//Also recommendation
    4. }
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. ui(new Ui::MainWindow),matrix(new Ui::Matrix)//here is what I changed
    2. {
    3. ui->setupUi(this);
    4. matrix->setupUi(this->ui->centralWidget);//Added this
    To copy to clipboard, switch view to plain text mode 

    I am at a bit of a dead end with how to approach this now hope someone can help
    Last edited by Robobulls; 23rd May 2013 at 19:26.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: WIdget relationship with Main Window

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. The following user says thank you to amleto for this useful post:


  4. #3
    Join Date
    May 2013
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: WIdget relationship with Main Window

    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.

  5. #4
    Join Date
    Feb 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: WIdget relationship with Main Window

    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 in the Qt Reference documentation? ()

    Karl

  6. #5
    Join Date
    May 2013
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: WIdget relationship with Main Window

    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

Similar Threads

  1. Customizable widget over main window.
    By SeeLook in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2012, 16:24
  2. Replies: 2
    Last Post: 16th April 2012, 04:13
  3. Add a Frame Widget to the main window
    By kamlmish in forum Qt Programming
    Replies: 2
    Last Post: 30th November 2010, 08:51
  4. Replies: 0
    Last Post: 14th November 2010, 19:38
  5. accessing my main application window widget
    By jayw710 in forum Newbie
    Replies: 8
    Last Post: 15th November 2007, 19:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.