简体   繁体   中英

Signal and slot Qt

I'm trying to write a very simple calendar program (I'm trying to learn Qt). The program itself is very basic, all it does is open a dialog box which displays today's date with a button next to it. When the button is pressed another dialog opens, which I'll call the calendar picker.

Here is the gist of the program: First, the main dialog opens with the current date. Then when the button shown in the picture is pushed, a signal is sent to a function which opens the picker and sets up a connection between the two classes which I'll describe below! The picker opens in which you can choose a date if you want. Let's say you choose a date by double clicking it. A signal is then sent to a function which closes the picker and the function then emits a signal to the main dialog to update the date to the new date. Now here's the problem:

Both the main dialog and the picker are in separate classes and I'm trying to set up a connection between the two classes when an item is double clicked.

***EDIT: Ok, now my problem is that I have Picker *mypicker declared in my header file and when I try using it in the .cpp file for example mypicker->show(); it causes the program to crash. Anyone know why?

Any help would be appreciated!!

undefined reference to MainDialog::updateDate(QDate)

Usually means that the compiler or the linker can't find the reference to it. So in your header, you make a promise that it will exist.

Then if when matching things up later the reference was never found... you get an error.

So what probably happened is one of a few things:

In your maindialog.cpp file you have:

// Either no definition of updateDate at all,  Wrong because you put in your header a declaration for one.

void updateDate(QDate date) // Wrong because it doesn't specify MainDialog
{

}


void MainDialog::updateDate() // Wrong because it doesn't match the parameter list
{

}

void MainDialog::updatedate(QDate date) // Wrong because the function name is off
{

}

QDate MainDialog::updateDate(QDate date) // Wrong because return type is off
{

}

void MainDialog::updateDate(QDate date) // Correct!  Matches the header file perfectly!
{

}

Then after you get past that, and other compile errors, keep an eye on the Application Output, because the connect call is a runtime connection, so it won't report a syntax mis-alignment until at the moment a connection is attempted.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM