如何在qt中从mainwindow调用对话框?

如何在qt中从mainwindow调用对话框?,qt,qt4,qcustomplot,Qt,Qt4,Qcustomplot,在这一行,编译器说发送方和接收方不兼容 我认为,当数据计时器超时时,图形对话框应该收到一个信号。它收到与否,我无法理解。请任何人查看此代码并告诉我如何调用插槽realtimeDataSlot() 插槽和信号必须具有相同数量的参数和类型。connect(&dataTimer,Signal(timeout()),此插槽(realtimeDataSlot(QCustomPlot*));信号和插槽必须具有相同的参数。谢谢Lwin Htoo Ko!现在问题是QCustomPlot*customPlot是在

在这一行,编译器说发送方和接收方不兼容

我认为,当数据计时器超时时,图形对话框应该收到一个信号。它收到与否,我无法理解。请任何人查看此代码并告诉我如何调用插槽
realtimeDataSlot()


插槽和信号必须具有相同数量的参数和类型。

connect(&dataTimer,Signal(timeout()),此插槽(realtimeDataSlot(QCustomPlot*));信号和插槽必须具有相同的参数。谢谢Lwin Htoo Ko!现在问题是QCustomPlot*customPlot是在ui_graph中定义的。如何在realtimeDataSlot()中使用它。实际上customPlot是一个小部件,它被升级为QCustomPlot。在这个小部件中,我尝试绘制graph我正在传递Customplot,因此此函数中没有问题,因为Customplot是Ui_graph的成员。但是如何在realtimeDataSlot()中访问Ui graph的同一成员。“ptr_Customplot=Customplot;”因此,ptr_Customplot与Ui_graph.Customplot相同。在realtimeDataSlot()中,可以使用ptr_CustomPlot,它与ui_graph.CustomPlot相同。
//functions for plotting graph
void MainWindow::opengraph()
{
    QDialog* graphdialog = new QDialog;
    Ui::graph ui_graph ;
    ui_graph.setupUi(graphdialog);

    setGeometry(400, 250, 542, 390);
    setWindowTitle("Graph");
    //statusBar()->clearMessage();
    //currentDemoIndex = demoIndex;
   ui_graph.customPlot->replot();

    RealtimeDataGraph(ui_graph.customPlot);
}

void MainWindow::RealtimeDataGraph(QCustomPlot *customPlot)
{
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
  QMessageBox::critical(this, "", "You're using Qt < 4.7, the realtime data demo needs functions that are available with Qt 4.7 to work properly");
#endif
  //demoName = "Real Time Data Demo";

  // include this section to fully disable antialiasing for higher performance:
  /*
  customPlot->setNotAntialiasedElements(QCP::aeAll);
  QFont font;
  font.setStyleStrategy(QFont::NoAntialias);
  customPlot->xAxis->setTickLabelFont(font);
  customPlot->yAxis->setTickLabelFont(font);
  customPlot->legend->setFont(font);
  */
  customPlot->addGraph(); // blue line
  customPlot->graph(0)->setPen(QPen(Qt::blue));
  customPlot->graph(0)->setBrush(QBrush(QColor(240, 255, 200)));
  customPlot->graph(0)->setAntialiasedFill(false);
  customPlot->addGraph(); // red line
  customPlot->graph(1)->setPen(QPen(Qt::red));
  customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));
  //
//  customPlot->addGraph(); // green line
//  customPlot->graph(2)->setPen(QPen(Qt::green));
//  customPlot->graph(0)->setChannelFillGraph(customPlot->graph(2));
  //

  customPlot->addGraph(); // blue dot
  customPlot->graph(2)->setPen(QPen(Qt::blue));
  customPlot->graph(2)->setLineStyle(QCPGraph::lsNone);
  customPlot->graph(2)->setScatterStyle(QCP::ssDisc);
  customPlot->addGraph(); // red dot
  customPlot->graph(3)->setPen(QPen(Qt::red));
  customPlot->graph(3)->setLineStyle(QCPGraph::lsNone);
  customPlot->graph(3)->setScatterStyle(QCP::ssDisc);

//  customPlot->addGraph(); // green dot
//  customPlot->graph(5)->setPen(QPen(Qt::green));
//  customPlot->graph(5)->setLineStyle(QCPGraph::lsNone);
//  customPlot->graph(5)->setScatterStyle(QCP::ssDisc);
//
  customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
  customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
  customPlot->xAxis->setAutoTickStep(false);
  customPlot->xAxis->setTickStep(2);
  customPlot->setupFullAxesBox();
  customPlot->xAxis->setLabel("Time(Sec)");
  customPlot->yAxis->setLabel("magnitude");

  // make left and bottom axes transfer their ranges to right and top axes:
  connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
  connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));

  // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
  *connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot(QCustomPlot *)));*
  dataTimer.start(0); // Interval 0 means to refresh as fast as possible
}

void MainWindow::realtimeDataSlot(QCustomPlot *customPlot)
{
  // calculate two new data points:
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
  double key = 0;
#else
  double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
#endif
  static double lastPointKey = 0;
  if (key-lastPointKey > 0.01) // at most add point every 10 ms
  {
    double value0 = sin(key*1.6+cos(key*1.7)*2)*10 + sin(key*1.2+0.56)*20 + 26;
    double value1 = sin(key*1.3+cos(key*1.2)*1.2)*7 + sin(key*0.9+0.26)*24 + 26;
    //
    //double value2 = sin(key*2+cos(key*2.2)*3)*17 + sin(key*2.3+0.76)*30 + 26;
    //
    // add data to lines:
    customPlot->graph(0)->addData(key, value0);
    customPlot->graph(1)->addData(key, value1);
    //
//    ui->customPlot->graph(1)->addData(key, value2);
    // set data of dots:
    customPlot->graph(2)->clearData();
    customPlot->graph(2)->addData(key, value0);
    customPlot->graph(3)->clearData();
    customPlot->graph(3)->addData(key, value1);

//    ui->customPlot->graph(5)->clearData();
//    ui->customPlot->graph(5)->addData(key, value2);
    // remove data of lines that's outside visible range:
    customPlot->graph(0)->removeDataBefore(key-20);
    customPlot->graph(1)->removeDataBefore(key-20);
//    ui->customPlot->graph(2)->removeDataBefore(key-20);
    // rescale value (vertical) axis to fit the current data:
    customPlot->graph(0)->rescaleValueAxis();
    customPlot->graph(1)->rescaleValueAxis(true);
//    ui->customPlot->graph(2)->rescaleValueAxis(true);
    lastPointKey = key;
  }
  // make key axis range scroll with the data (at a constant range size of 8):
  customPlot->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
  customPlot->replot();

  // calculate frames per second:
  static double lastFpsKey;
  static int frameCount;
  ++frameCount;
  if (key-lastFpsKey > 2) // average fps over 2 seconds
  {
    //ui->statusBar->showMessage(
//          QString("%1 FPS, Total Data points: %2")
//          .arg(frameCount/(key-lastFpsKey), 0, 'f', 0)
//          .arg(ui->customPlot->graph(0)->data()->count()+ui->customPlot->graph(1)->data()->count())
//          , 0);
    lastFpsKey = key;
    frameCount = 0;
  }
}
connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot(QCustomPlot *)));
QCustomPlot * ptr_CustomPlot; // pointer of QCustomPlot

//functions for plotting graph
void MainWindow::opengraph()
{
    QDialog* graphdialog = new QDialog;
    Ui::graph ui_graph ;
    ui_graph.setupUi(graphdialog);

    setGeometry(400, 250, 542, 390);
    setWindowTitle("Graph");
    ui_graph.customPlot->replot();
    RealtimeDataGraph(ui_graph.customPlot);
}

void MainWindow::RealtimeDataGraph(QCustomPlot *customPlot)
{
  ptr_CustomPlot = customPlot; // here, customPlot is saved to ptr_CustomPlot
  /* ... */

  // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
  connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));

}

void MainWindow::realtimeDataSlot()
{
  /* use ptr_CustomPlot // here, ptr_CustomPlot is the same as customPlot which is also ui_graph.customPlot */
  /* ... */
}