Ryan111
1st April 2015, 14:45
Hi
I have written this program:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString R,G,B;
int r,g,b,w;
char *ptr;
QString hex = ui->lineEdit->text();
R[0] = hex[0];
R[1] = hex[1];
G[0] = hex[2];
G[1] = hex[3];
B[0] = hex[4];
B[1] = hex[5];
r = (int)strtol( R , &ptr , 16 );
g = (int)strtol( G , &ptr , 16 );
b = (int)strtol( B , &ptr , 16 );
r = ( r & 0xF8);
g = ( g & 0xFC);
b = ( b & 0xF8);
w = r;
w = w<<6;
w = g;
w = w<<5;
w = b;
ui->lineEdit->setText(QString::number( w, 16 ));
}
this program is supposed to get a 24bit hex RGB and convert it to a 16bit hex RGB. this is 24bit:
http://www.willamette.edu/~gorr/classes/GeneralGraphics/imageFormats/24bits.gif
and this is 16bit:
http://upload.wikimedia.org/wikipedia/commons/f/f2/SLNotation56500.png
then we have to remove 3bit of red and blue color and 2bit of green color.
the problem is that strtol function cannot convert QString to const char. actually I get this error:
http://upload.tehran98.com/upme/uploads/f078a5e93ec0099e1.png
How can I figure out this problem?
I have written this program:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString R,G,B;
int r,g,b,w;
char *ptr;
QString hex = ui->lineEdit->text();
R[0] = hex[0];
R[1] = hex[1];
G[0] = hex[2];
G[1] = hex[3];
B[0] = hex[4];
B[1] = hex[5];
r = (int)strtol( R , &ptr , 16 );
g = (int)strtol( G , &ptr , 16 );
b = (int)strtol( B , &ptr , 16 );
r = ( r & 0xF8);
g = ( g & 0xFC);
b = ( b & 0xF8);
w = r;
w = w<<6;
w = g;
w = w<<5;
w = b;
ui->lineEdit->setText(QString::number( w, 16 ));
}
this program is supposed to get a 24bit hex RGB and convert it to a 16bit hex RGB. this is 24bit:
http://www.willamette.edu/~gorr/classes/GeneralGraphics/imageFormats/24bits.gif
and this is 16bit:
http://upload.wikimedia.org/wikipedia/commons/f/f2/SLNotation56500.png
then we have to remove 3bit of red and blue color and 2bit of green color.
the problem is that strtol function cannot convert QString to const char. actually I get this error:
http://upload.tehran98.com/upme/uploads/f078a5e93ec0099e1.png
How can I figure out this problem?