QTimer::singleShot(8500, this, SLOT(searchTable(50)));
First thing: this is not allowed. You cannot pass an argument in a connect() statement (which is what this does, in effect - it says to connect the QTimer's timeout() signal to your searchTable() slot). However the function signatures for the signal and slot must match. QTimer::timeout() does not pass any arguments, so you can't make something up for it to pass to your slot.
QObject::connect: No such slot MainWindow::searchTable(50) in ../NewApp/mainwindow.cpp:70
Second, this occurs because SLOT() is a C++ macro, which converts its argument into a literal string. So your SLOT() argument is being passed as the string "searchTable(50)" and internally the connect() method is trying to match it up with a method defined in MainWindow named "searchTable(50)", which of course there isn't one. That's what the compiler error message is telling you.
So, if what you want to do is to fire off an initial search of the table 8500 ms after your program starts (technically, 8500 ms after the MainWindow constructor exits), then you need to create a slot that takes no arguments, connect that to the timeout signal, then within that slot, call searchTable( 50 ):
private slots: // in MainWindow class
void doInitialSearch();
void searchTable( int searchID );
private slots: // in MainWindow class
void doInitialSearch();
void searchTable( int searchID );
To copy to clipboard, switch view to plain text mode
MainWindow
::MainWindow(QWidget *parent
): ui(new Ui::MainWindow)
{
ui->setupUi(this);
// SEARCH TABLE UPDATE
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(searchTable(int)));
// LOAD TABLES
QTimer::singleShot( 8500,
this,
SLOT( doInitialSearch
() ) );
// etc..
}
void MainWindow::doInitialSearch()
{
searchTable( 50 );
}
void MainWindow::searchTable(int searchID)
{
//my code
}
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// SEARCH TABLE UPDATE
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(searchTable(int)));
// LOAD TABLES
QTimer::singleShot( 8500, this, SLOT( doInitialSearch() ) );
// etc..
}
void MainWindow::doInitialSearch()
{
searchTable( 50 );
}
void MainWindow::searchTable(int searchID)
{
//my code
}
To copy to clipboard, switch view to plain text mode
What are you trying to do with this 8 1/2 second delay before you do the initial search? There are probably better ways to do it than make your user sit and watch the main window for that long while nothing happens.
If all you want is to ensure that the MainWindow is visible before doing this search, then you can implement an override of the showEvent() and make a direct call to searchTable() in that:
{
QMainWindow::showEvent( pEvent
);
// same as super.showEvent() in python
searchTable( 50 );
}
void MainWIndow::showEvent( QShowEvent * pEvent )
{
QMainWindow::showEvent( pEvent ); // same as super.showEvent() in python
searchTable( 50 );
}
To copy to clipboard, switch view to plain text mode
or you can use a QTimer with zero timeout to accomplish the same thing. The timer signal will fire immediately after control returns to the Qt event loop (ie. after the showEvent() method exits).
{
QMainWindow::showEvent( pEvent
);
// same as super.showEvent() in python
QTimer::singleShot( 0,
this,
SLOT( doInitialSearch
() ) );
}
void MainWIndow::showEvent( QShowEvent * pEvent )
{
QMainWindow::showEvent( pEvent ); // same as super.showEvent() in python
QTimer::singleShot( 0, this, SLOT( doInitialSearch() ) );
}
To copy to clipboard, switch view to plain text mode
But I suspect there is no need for you to wait for the MainWindow to be visible before doing the initial search. Even if the window is not visible, all of the QWidgets in it are complete after the call to setupUi(), so you can fill tables, etc. and they will become visible when the MainWindow does.
Bookmarks