QFont fromString() toString() bug

Discuss anything related to product development
Post Reply
seasoned_geek
Posts: 253
Joined: Thu Jun 11 2020 12:18 pm

QFont fromString() toString() bug

Post by seasoned_geek »

All,

Ubuntu 20.04 LTS
Built from tip of tip on Saturday.

Code: Select all

m_ui->headerFontLE->text():  Monospace,10,-1,5,50,0,0,0,0,0,12,-1,5,50,0,0,0,0,0 

QFont::fromString: Invalid description 'Monospace,10,-1,5,50,0,0,0,0,0,12,-1,5,50,0,0,0,0,0'
done saving header font

m_ui->footerFontLE->text():  Monospace,10,-1,5,50,0,0,0,0,0,12,-1,5,50,0,0,0,0,0 

QFont::fromString: Invalid description 'Monospace,10,-1,5,50,0,0,0,0,0,12,-1,5,50,0,0,0,0,0'
done saving footer font
The Line Edits hold the toString() output. When saving I fetch the text and attempt to translated it back.

Code: Select all

void DialogPrintOptions::saveSettings()
{
    QFont fnt;

    if ( m_ui->headerFontLE->text().length() > 5 )
    {
        qDebug() << "m_ui->headerFontLE->text(): " << m_ui->headerFontLE->text() << "\n";
        fnt.fromString( m_ui->headerFontLE->text() );
        Overlord::getInstance()->setHeaderFont( fnt );
        qDebug() << "done saving header font\n";
    }

    if ( m_ui->footerFontLE->text().length() > 5 )
    {
        qDebug() << "m_ui->footerFontLE->text(): " << m_ui->footerFontLE->text() << "\n";
        fnt.fromString( m_ui->footerFontLE->text() );
        Overlord::getInstance()->setFooterFont( fnt );
        qDebug() << "done saving footer font\n";
    }

It would also really help if the "Invalid description" actually specified what it was looking for.

The Line Edit is read only. Has to be changed by a font selector.

Adding insult to injury, when the fromString() fails, it appears to default to "Sans Serif"

https://www.logikalsolutions.com/wordpress/wp-content/uploads/2022/11/defaults-to-sans-serif.png
seasoned_geek
Posts: 253
Joined: Thu Jun 11 2020 12:18 pm

Re: QFont fromString() toString() bug

Post by seasoned_geek »

Saw a bunch of new code checked in. Built from tip of tip. This has now been fixed. I didn't touch anything in my code yet today.
Post Reply