SOLVED: error: no match for ‘operator=’



  • I am getting the following error:

    /home/myuser/program/MyGateway/protocol/iridium/mailbox.cpp: In member function ‘QList<InmarsatMessage> IridiumMailbox::getInmarsatMessages()’:
    /home/myuser/program/MyGateway/protocol/iridium/mailbox.cpp:171:54: error: no match for ‘operator=’ in ‘msg.InmarsatMessage::time = inmarsat_time.QDateTime::setTimeSpec((Qt::TimeSpec)1u)’
    /home/myuser/program/MyGateway/protocol/iridium/mailbox.cpp:171:54: note: candidate is:
    /usr/include/qt4/QtCore/qdatetime.h:225:16: note: QDateTime& QDateTime::operator=(const QDateTime&)
    /usr/include/qt4/QtCore/qdatetime.h:225:16: note: no known conversion for argument 1 from ‘void’ to ‘const QDateTime&’

    It's about this line of code right here:

    QDateTime inmarsat_time = QDateTime::fromString(message->received().toString(), "ddd MMM d HH:mm:ss yyyy");

    That function received() is here:

    QDateTime ImapMessage::received (void) const {
    return(d->received);
    }

    Any idea why I am getting this error?


  • Moderators

    Hi,

    Your error line is
    @
    msg.InmarsatMessage::time = inmarsat_time.QDateTime::setTimeSpec((Qt::TimeSpec)1u)
    @

    That's not valid C++. What is your goal here?

    [quote]
    @
    QDateTime inmarsat_time = QDateTime::fromString(message->received().toString(), “ddd MMM d HH:mm:ss yyyy”);
    @
    [/quote]This line is valid. But why do you convert a QDateTime to QString, and then convert it back to QDateTime again?



  • But there is no line of code as such:

    msg.InmarsatMessage::time = inmarsat_time.QDateTime::setTimeSpec((Qt::TimeSpec)1u)

    That error is pointing to this line of code:

    QDateTime inmarsat_time = QDateTime::fromString(message->received().toString(), “ddd MMM d HH:mm:ss yyyy”);
    

  • Moderators

    Please use "code wrappings":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 to structure your post.
    Code wrappings improve reading of your code and error listing sections significantly.


  • Moderators

    [quote]But there is no line of code as such:
    msg.InmarsatMessage::time = inmarsat_time.QDateTime::setTimeSpec((Qt::TimeSpec)1u)[/quote]You're right; I didn't realize GCC expands code in its error messages.

    [quote]That error is pointing to this line of code:
    QDateTime inmarsat_time = QDateTime::fromString(message->received().toString(), “ddd MMM d HH:mm:ss yyyy”);[/quote]
    Hmm, I can't see any errors in that line. What is your compiler version?

    Anyway, why do you call toString() and then fromString() again? Just assign message->received() directly to inmarsat_time. Your code will be simpler, and the error might go away.

    P.S. I agree with koahnig. Your code and errors were hard to read.



  • So I was able to make the error go away by changing this:

    @ QDateTime inmarsat_time = message->received();
    msg.time = inmarsat_time.setTimeSpec(Qt::UTC);
    @
    to this:

    @ QDateTime inmarsat_time = message->received();
    msg.time.setTimeSpec(Qt::UTC);@

    Why does the latter work and not the former?


  • Moderators

    [quote]That error is pointing to this line of code:
    QDateTime inmarsat_time = QDateTime::fromString(message->received().toString(), “ddd MMM d HH:mm:ss yyyy”);[/quote]The error was NOT pointing to the line above. It was pointing to this one:
    [quote]
    @msg.time = inmarsat_time.setTimeSpec(Qt::UTC);@
    [/quote]setTimeSpec() returns void. You can't assign void to msg.time



  • ok didn't realize setTimeSpec() returned void.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.