无法在multiMap C ++中插入QCustomPlot :: QCPGraph

时间:2017-05-31 13:20:09

标签: c++ qt plot multimap qcustomplot

我正在开发一个程序,需要将QCPGraph从QCustomPlot FrameWork插入std::multimap。注意:我仍然是C ++的新手。但是,我无法让这个工作,这真的令人沮丧。

这是我的代码:

ui->customPlot->addGraph();        

/*
  fill graph with some data
*/

QCPGraph *graph = ui->customPlot->graph(0); 

std::multimap<int, std::pair<std::vector<double>, QCPGraph>, _comparator> myMap; 

//just for demo
std::vector<double> vec; 
vec.at(0) = 2.2; 

myMap.insert(std::make_pair(1, std::make_pair(vec, graph)));

最后一行给出了以下编译器错误:

C:\path\mainwindow.cpp:178: Error: no matching function for call to 'std::multimap<int, std::pair<std::vector<double>, QCPGraph>, MainWindow::__comparator>::insert(std::pair<int, std::pair<std::vector<double>, QCPGraph*> >)'
     myMap.insert(std::make_pair(1, std::make_pair(vec, graph)));
                                                                 ^

C:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\c++\bits\stl_multimap.h:524: Error: no type named 'type' in 'struct std::enable_if<false, void>'
       template<typename _Pair, typename = typename
                                ^

我知道它可能与指针和类型有关,但我无法弄明白。我试着给&graph(*graph)插入,这也没用。请帮忙。

1 个答案:

答案 0 :(得分:0)

您的容器是:

std::pair<const int, std::pair<std::vector<double>, QCPGraph>>

所以它的value_type是:

QCPGraph *graph = ui->customPlot->graph(0); 

所以当你有一个:

myMap.insert(std::make_pair(1, std::make_pair(vec, *graph)));

您需要像这样插入:

myMap.emplace(1, std::make_pair(vec, *graph));

或者在C ++ 11中:

std::multimap<int, std::pair<std::vector<double>, QCPGraph*>> myMap; 
myMap.emplace(1, std::make_pair(vec, graph));

但我认为图表是由QCustomPlot拥有的,所以你应该存储一个指向它的指针:

$( document ).ready(function() {
$('a *').css('top',''); // For Remove specific property of child element

$('a').css('top',''); // For Remove specific property of element
});