輸出空白行
$ echo -e "\r" > file.txt如果 \r 不行的話 可以改成 \n 。
如果有問題的話記得使用 –x 除錯。例如
$ sh –x shell_script
my 3 or 2 words; thinkness, speakless
輸出空白行
$ echo -e "\r" > file.txt如果 \r 不行的話 可以改成 \n 。
$ sh –x shell_script
台灣的幾種金流平台先記一下,可直接到超商列印付款繳費,不會留下個人資料。
【參考】
有點類似sed/awk,Perl 的強項在於比對字串,比如說想比對檔案內特定的字串你必須要做幾件事
Makefile 的參數
FLAGS+=-DDEBUG
include Config.in
all:
gcc -o hello hello.c ${FLAGS}
#include <stdio.h>
int main(void)
{
#if (DEBUG)
printf("DEBUG=1\n");
#else
printf("DEBUG=0\n");
#endif
return 0;
}以下簡單記一下 Perl 的簡單用法
【目的】
【環境】
【程式】
創造一個Dialog。放置一個 pushButton。 並加入下面的程式碼。其中重要的部分如下。
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
this->setGeometry(0, 0, 170, 334);
this->setStyleSheet("background-image: url(background.jpg)");
this->setMask(QRegion(0, 0, 170, 334, QRegion::Rectangle));
//this->setAcceptDrops(true);
//this->setAutoFillBackground(true);
//setWindowOpacity(1);
ui->setupUi(this);
}
void Dialog::on_pushButton_clicked()
{
close();
}
class Dialog : public QDialog {
Q_OBJECT
...
void on_pushButton_clicked();
};
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>397</width>
<height>489</height>
</rect>
</property>
<property name="windowTitle">
<string>Emulator</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>18</x>
<y>305</y>
<width>30</width>
<height>10</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
結果 123 【結果】
【問題】
#include <QPixmap>
#include <QPalette>
#include <QBrush>
#include <QFile>
#include <QBitmap>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
QString fn = "../tux.png";
if (!QFile::exists(fn))
exit(1);
QPixmap pixmap("../tux.png");
QPalette palette;
palette.setBrush(w.backgroundRole(), QBrush(pixmap));
w.setPalette(palette);
w.setFixedSize( pixmap.size() );
w.setMask(pixmap.mask());
w.show();
return a.exec();
}
呈現結果 (底下的小企鵝就是整個不規則視窗)
setWindowFlags(Qt::FramelessWindowHint);
【參考】
【目的】
【原理】
【程式】
http://www.google.com/ig/api?hl=us&weather=taipei
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
HttpGet getter;
QUrl url("http://www.google.com/ig/api?hl=us&weather=taipei");
getter.downloadFile(QUrl(url));
QObject::connect(&getter, SIGNAL(finished()), &w, SLOT(show_weather()));
return a.exec();
}
由於我們不需更改資料,所以以 SAX 先作實驗
(tbd)
透過 DOM 的方式 (通常可用 QTreeWidgetItem搭配遞迴方式載入,此處使用苦工方式一個一個讀出)
dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QUrl>
#include "HttpGet.h"
#include <iostream>
#include <QtXml>
#include <QFile>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog {
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
protected:
void changeEvent(QEvent *e);
private:
Ui::Dialog *ui;
private slots:
void show_weather();
void show_forecast_information(const QDomNode node3);
void show_current_conditions(const QDomNode node3);
void show_forecast_conditions(const QDomNode node3);
};
#endif // DIALOG_H
dialog.cpp
void Dialog::show_weather()
{
QDomDocument doc;
QFile file("api");
QString errorStr;
int errorLine;
int errorCol;
if(!doc.setContent(&file,true,&errorStr,&errorLine,&errorCol)){
qDebug() << "Unable to open the file";
return;
}
file.close();
QDomElement root = doc.documentElement();
if (root.tagName() != "xml_api_reply")
return;
QDomNode node2 = root.firstChild();
if(node2.toElement().tagName() == "weather")
{
QDomNode node3 = node2.firstChild();
while (!node3.isNull()){
qDebug() << "-" << node3.toElement().tagName();
if(node3.toElement().tagName() == "forecast_information")
show_forecast_information(node3);
else if (node3.toElement().tagName() == "current_conditions")
show_current_conditions(node3);
else if (node3.toElement().tagName() == "forecast_conditions")
show_forecast_conditions(node3);
node3 = node3.nextSibling();
}
}
}
void Dialog::show_forecast_information(const QDomNode node3)
{
QDomNode node4 = node3.firstChild();
while (!node4.isNull()){
if(node4.toElement().tagName() == "city")
qDebug() << " +city:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "postal_code")
qDebug() << " +postal_code:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "latitude_e6")
qDebug() << " +latitude_e6:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "forecast_date")
qDebug() << " +forecast_date:" << node4.toElement().attribute("humidity");
else if(node4.toElement().tagName() == "current_date_time")
qDebug() << " +current_date_time:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "unit_system")
qDebug() << " +unit_system:" << node4.toElement().attribute("data");
node4 = node4.nextSibling();
}
}
void Dialog::show_current_conditions(const QDomNode node3)
{
QDomNode node4 = node3.firstChild();
while (!node4.isNull()){
if(node4.toElement().tagName() == "condition")
qDebug() << " +condition:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "temp_f")
qDebug() << " +temp_f:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "temp_c")
qDebug() << " +temp_c:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "humidity")
qDebug() << " +humidity:" << node4.toElement().attribute("humidity");
else if(node4.toElement().tagName() == "icon")
qDebug() << " +icon:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "wind_condition")
qDebug() << " +wind_condition:" << node4.toElement().attribute("data");
node4 = node4.nextSibling();
}
}
void Dialog::show_forecast_conditions(const QDomNode node3)
{
QDomNode node4 = node3.firstChild();
while (!node4.isNull()){
if(node4.toElement().tagName() == "day_of_week")
qDebug() << " +day_of_week:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "low")
qDebug() << " +low:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "high")
qDebug() << " +high:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "icon")
qDebug() << " +icon:" << node4.toElement().attribute("data");
else if(node4.toElement().tagName() == "condition")
qDebug() << " +condition:" << node4.toElement().attribute("data");
node4 = node4.nextSibling();
}
}
- "forecast_information"
+city: "taipei"
+postal_code: "taipei"
+latitude_e6: ""
+forecast_date: ""
+current_date_time: "2010-09-29 23:00:00 +0000"
+unit_system: "US"
- "current_conditions"
+condition: "Clear"
+temp_f: "82"
+temp_c: "28"
+humidity: ""
+icon: "/ig/images/weather/sunny.gif"
+wind_condition: "Wind: mph"
- "forecast_conditions"
+day_of_week: "Thu"
+low: "75"
+high: "87"
+icon: "/ig/images/weather/rain.gif"
+condition: "Rain"
- "forecast_conditions"
+day_of_week: "Fri"
+low: "77"
+high: "89"
+icon: "/ig/images/weather/cloudy.gif"
+condition: "Cloudy"
- "forecast_conditions"
+day_of_week: "Sat"
+low: "77"
+high: "91"
+icon: "/ig/images/weather/cloudy.gif"
+condition: "Cloudy"
- "forecast_conditions"
+day_of_week: "Sun"
+low: "73"
+high: "86"
+icon: "/ig/images/weather/rain.gif"
+condition: "Rain"
【其它】
【參考】
Ed32. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com