Hi,
I try to take window from QWorkspace. But it doesn't work:
Code:
m_tablePanel = (TabelPanel *)(workspace->windowList()).at(0);
Thank you!
Printable View
Hi,
I try to take window from QWorkspace. But it doesn't work:
Code:
m_tablePanel = (TabelPanel *)(workspace->windowList()).at(0);
Thank you!
Please define what you mean by "it doesn't work".
I cannot update my Plot.
Attachment 9452
I'm a little ashamed for my code. But this is my first MDI program.
There is a little code:
Code:
m_tablePanel = (TabelPanel *)(workspace->windowList()).at(0); m_plotPanel = (PlotPanel *)(workspace->windowList()).at(1); connect(m_tablePanel, SIGNAL(itemChanged(QStandardItem *)), this, SLOT(updatePanel(QStandardItem*)));
Maybe you can't update your plot but it doesn't mean the method doesn't work. Especially that you have an ugly C cast instead of qobject_cast or something similar. How do you know that the first item in the list is an instance of TablePanel and the second one is an instance of PlotPanel?
I want to take instance of TablePanel and PlotPanel from workspace. I don't know how to do it.
It's doesn't work:
Code:
m_tablePanel = qobject_cast<TabelPanel *>((workspace->windowList()).at(0)); m_plotPanel = qobject_cast<PlotPanel *>((workspace->windowList()).at(1));
I added the Table then the Plot.
Code:
workspace->addWindow(tablePanel); workspace->addWindow(plotPanel);
Slot of MainWindow updatePanel() doesn't work.
Code:
connect(m_tablePanel, SIGNAL(itemChanged(QStandardItem *)), this, SLOT(updatePanel(QStandardItem*)));
I set a breakpoint in updatePanel() SLOT
You set a breakpoint and?
Apparently your signal-slot connection is invalid.
TablePanel class is unlikely to have a signal itemChanged() carrying a QStandardItem pointer unless you added such signal to the class yourself.
Thanks! Now the breakpoint works.
Code:
But the Plot is not redrawn.
plotpanel.cpp
Code:
#include "plotpanel.h" #include <QHBoxLayout> #include <QDebug> #include <qwt_plot_curve.h> #include <qwt_symbol.h> { mainLayout->addWidget(plot); this->setLayout(mainLayout); } { curve->setTitle(tr("Points")); curve->setSymbol(symbol); QPolygonF points; double x, y; for (int row = 0; row < model->rowCount(); row++) { x = model->data(index).toDouble(); index = model->index(row, 1); y = model->data(index).toDouble(); } curve->setSamples(points); curve->attach(plot); // this->update(); }
I don't see you calling replot() on the plot anywhere.
Thanks! Thanks! Thanks! :)
There is an another problem. I wanna see the new plot. How to delete the old plot?
Attachment 9458
Why not reuse the old curve instead?
Maybe I must delete the old curve? How to do it? I don't understand...
If you want to remove the old curve then detach it from the plot and delete it.
How to get the old curve?
You can store it in some member variable and then retrieve it later when you need it.
Nice! It works! Thank you much :)
Attachment 9459
This program is still left unfinished. But it may be useful for someone.
I made a loading (saving) table from (to) a xml-file:
Table.xml
Attachment 9461Quote:
<Table nrows="5" ncols="2">
<point x="0.02" y="0.33"/>
<point x="0.56" y="1.12"/>
<point x="2.22" y="2.33"/>
<point x="6.23" y="4.87"/>
<point x="9.55" y="8.23"/>
</Table>
I replace QWorkspace -> QMdiArea
Code:
//workspace = new QWorkspace; mdiArea = new QMdiArea; //setCentralWidget( workspace ); setCentralWidget( mdiArea ); createActions(); createMenus(); createToolbars(); showScenePanel(); showControlPanel(); scenePanel = new ScenePanel; //scenePanel = qobject_cast<ScenePanel *>((workspace->windowList()).at(0)); scenePanel = qobject_cast<ScenePanel *>((mdiArea->subWindowList()).at(0)); controlPanel = new ControlPanel; //controlPanel = qobject_cast<ControlPanel *>((workspace->windowList()).at(1)); controlPanel = qobject_cast<ControlPanel *>((mdiArea->subWindowList()).at(1));
But the program crashes at run time (on the red line)
Comment lines #15 and #18 in the above code
I did it. The program isn't crushed.
But I see:
Attachment 9467
My Project:
Here is corrected code...
I have ran it with "QWorkspase". It worked normally.
Thanks! It works.
But program works illegal.
Added after 5 minutes:
How to do that:
Code:
scenePanel = qobject_cast<ScenePanel *>(windows.at(0)); controlPanel = qobject_cast<ControlPanel *>(windows.at(1));
Thank you very much :)
Added after 40 minutes:
In addition, instead:
Code:
scenePanel->resize(500, 500);
I wrote
Code:
sceneWindow->resize(500, 500);
Guys, thanks for help! I am happy :D
This won't work because the returned widget is an instance of QMdiSubWindow and not your widget.
Santosh Reddy have corrected:
mainwindow.h
Code:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "controlpanel.h" #include "scenepanel.h" class QAction; class QMdiSubWindow; class QMdiArea; class QMenu; { Q_OBJECT public: signals: public slots: private: void createActions(); void createMenus(); void createToolbars(); QMdiArea *mdiArea; QAction *sceneAction; QAction *controlAction; ScenePanel *scenePanel; ControlPanel *controlPanel; QMdiSubWindow * sceneWindow; QMdiSubWindow * controlWindow; private slots: void showScenePanel(); void showControlPanel(); }; #endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h" #include <QtGui> { this->setWindowTitle(tr("mdiLine")); mdiArea = new QMdiArea; setCentralWidget( mdiArea ); createActions(); createMenus(); createToolbars(); scenePanel = new ScenePanel; sceneWindow = mdiArea->addSubWindow(scenePanel); sceneWindow->resize(500, 500); controlPanel = new ControlPanel; controlWindow = mdiArea->addSubWindow(controlPanel); connect(controlPanel, SIGNAL(drawLine(QVector3D,QVector3D)), scenePanel, SLOT(drawLine(QVector3D,QVector3D))); showScenePanel(); showControlPanel(); } void MainWindow::createActions() { sceneAction->setStatusTip( tr("Scene Panel") ); connect( sceneAction, SIGNAL(triggered()), this, SLOT(showScenePanel()) ); controlAction->setStatusTip( tr("Control Panel") ); connect( controlAction, SIGNAL(triggered()), this, SLOT(showControlPanel()) ); } void MainWindow::createMenus() { QMenu *menu; menu = menuBar()->addMenu( tr("&Panels") ); menu->addAction( sceneAction ); menu->addAction( controlAction ); } void MainWindow::createToolbars() { QToolBar *toolbar; toolbar = addToolBar( tr("Panels") ); toolbar->addAction( sceneAction ); toolbar->addAction( controlAction ); } void MainWindow::showScenePanel() { sceneWindow->show(); } void MainWindow::showControlPanel() { controlWindow->show(); }