Assuming you're using QGIS >= 1.6.0. There is a geoalgorithm called "Polygons to lines" accessible via Vector > Geometry Tools > Polygons to Lines
(otherwise search in the Processing Toolbox Ctrl+Alt+T), which will create a new shapefile with all the attributes of the original.
For PyQGIS it is native"native:polygonstolinespolygonstolines"
>>> processing.algorithmHelp("native:polygonstolines")
Polygons to lines (native:polygonstolines)
Converts polygons to lines.
Converts polygons to lines
----------------
Input parameters
----------------
INPUT: Input layer
Parameter type: QgsProcessingParameterFeatureSource
Accepted data types:
- str: layer ID
- str: layer name
- str: layer source
- QgsProcessingFeatureSourceDefinition
- QgsProperty
- QgsVectorLayer
OUTPUT: Lines
Parameter type: QgsProcessingParameterFeatureSink
Accepted data types:
- str: destination vector file, e.g. 'd:/test.shp'
- str: 'memory:' to store result in temporary memory layer
- str: using vector provider ID prefix and destination URI, e.g. 'postgres:…' to store result in PostGIS table
- QgsProcessingOutputLayerDefinition
- QgsProperty
----------------
Outputs
----------------
OUTPUT: <QgsProcessingOutputVectorLayer>
Lines