Passing another argument to a SLOT
-
OK, the simply answer is: you can't .
-
Or use a qsignalmapper to "parse" the signals into slots with other arguments.
-
Like the others said, it's not possible to have a slot with more arguments than the signal.
Use an intermediate slot that will call your function with the necessary parameters.
Also, are you sure you want to use pointers to QString and int in your slot ?
-
@void mainWind::changetab(int index)
{
if(ui->tabWidget->indexOf(ui->newtab)==index)
{
addtab();}
currentpage(()->settings()->setIconDatabasePath("a");
url(currentPages()->url());
connect(currentpage((),SIGNAL(loadProgress(int)),ui->progressBar,SLOT(setValue(int)));
connect(currentpage((),SIGNAL(loadStarted()),this,SLOT(depart()));
connect(currentpage((),SIGNAL(loadFinished(bool)),this,SLOT(finish(bool)));
connect(currentpage((),SIGNAL(loadProgress(int)),this,SLOT(laodPage(int)));
connect(currentpage((),SIGNAL(titleChanged(QString)),this,SLOT(titl(QString)));
connect(currentpage((),SIGNAL(urlChanged(QUrl)),this,SLOT(url(QUrl)));
connect(currentpage((),SIGNAL(iconChanged()),this,SLOT(icon()));}@
@
QWebView *mainWind:: currentpage()
{
if(ui->tabWidget->currentWidget()->findChild<QWebView *>()==0)
{
int a=ui->tabWidget->currentIndex()-1;
return ui->tabWidget->widget(a)->findChild<QWebView *>();} else { return ui->tabWidget->currentWidget()->findChild<QWebView *>(); }
}
@
@
void mainWind::titre(const QString & titre)
{
QString titr(titre);
if(titre.size()>40)
{
titr=titre.left(40)+"....";
}
ui->tabWidget->setTabText(m_index,titr);
}
@
so when i load a page and I dont change the tab all is ok. but when i leave the page to load and i change the tab. the name of the page load is in the newtab because it is now the current tab. i have the page in a tab and its name in the other tab.
so thats why i want to pass index of the widget (that well be changing the titl -
Then in your slot use sender() to get the widget that emitted the signal and use that to find the right tab to update.
-
sender() returns a pointer to the object that emitted the signal. In your case (if I understood correctly) it's one of the widget in the QTabWidget.
You can cast (using qobject_cast) that pointer to QWidget * and then get the tab index using indexOf and update the correct tab text with it.
-
thx
[quote author="SGaist" date="1377806355"]sender() returns a pointer to the object that emitted the signal. In your case (if I understood correctly) it's one of the widget in the QTabWidget. [/quote]but the QObject that emitted the signal is a QWebView which is contain in a QTabWidget can i have a access to the tab with a pointer of QWebView
fanction like "findChild" but in this one i have to find the parent
thx again -
You don't need that, since you call addTab with a QWebView you can retrieve the corresponding index with the pointer given by sender() once you casted it.
-
QObject * QObject::sender() const [protected] where do i declare this methode, in which slot.
i have also this slot
@void mainWind::addtap()
{
QWidget *tap=new QWidget();
QVBoxLayout *layout = new QVBoxLayout();
QWebView *webpage=new QWebView();
pageWeb->settings()->setIconDatabasePath("a");
layout->addWidget(webpage);
tap->setLayout(layout);
webpage->load(QUrl(""));
ui->tabWidget->insertTab(ui->tabWidget->indexOf(ui->newTap),tap,"");
ui->tabWidget->setCurrentWidget(tap);
changetap(ui->tabWidget->indexOf(tap));}@
-
You don't declare that method. You call it at the start of the slot
-
see the doc of "QObject::sender()":http://qt-project.org/doc/qt-4.8/qobject.html#sender .
-