2012-08-23 68 views
0

我試圖用qwtslider連接qcombobox,並且在combox,mm和像素上有兩個選項。我想在選擇該選項時將比例更改爲像素或mms。我已經創造了一些功能插槽工作,而這些都是:連接帶滑塊的combox

void planevolume::mm() 
{ 
     ui->Slider->setRange(xmin, xmax/(256/3), 1.0/(256/3)); 
     ui->Slider->setScale(xmin, (xmax+1)/(256/3), ((xmax+1)/16)/(256/3)); 
     connect(ui->Slider, SIGNAL(valueChanged(double)), ui->lcdNumber, SLOT(display(double))); 
} 

void planevolume::pixel() 
{ 
     ui->Slider->setRange(xmin, xmax, 1.0); 
     ui->Slider->setScale(xmin, xmax+1, (xmax+1)/16); 
     connect(ui->Slider, SIGNAL(valueChanged(double)), ui->lcdNumber, SLOT(display(double))); 
} 

,我想我可能會使用來自連接箱的信號連接它們。我的連接盒是這樣的:

ui->comboBox->insertItem(1, QString("pixel")); 
    ui->comboBox->insertItem(2, QString("mm")); 

而且他們創造一個插槽可供選擇:

void planevolume::currentIndexPixel() 
{ 
    ui->comboBox->currentIndex(1); 
} 

void planevolume::currentIndexMM() 
{ 
    ui->comboBox->currentIndex(2); 
} 

連接它們像這樣:

connect(this, SIGNAL(currentIndexPixel()),ui->Slider, SLOT(pixel())); 
connect(this, SIGNAL(currentIndexMM()),ui->Slider, SLOT(mm())); 

,但我發現這樣的錯誤,我不知道我做錯了什麼:

error: no matching function for call to ‘QComboBox::currentIndex(int)’ 
/usr/include/qt4/QtGui/qcombobox.h:184: note: candidates are: int QComboBox::currentIndex() const 

回答

1

我想你的意思是使用setCurrentIndex(),而不是currentIndex()currentIndexPixelcurrentIndexMM功能

+0

一樣,我得到的'planevolume :: currentIndexPixel() 多個定義「和planevolume的'多個定義:: currentIndexMM()」 – SamuelNLP

+0

我試着用void activated(int index)和void currentIndexChanged(int index),但我知道它們受到保護... – SamuelNLP

+0

我想我會使用兩個按鈕,因爲我認爲它會使我的工作更輕鬆。 – SamuelNLP