小编use*_*175的帖子

Qt - 从文本文件中读取

我有一个有三列的表视图; 我刚刚使用此代码传入写入文本文件

QFile file("/home/hamad/lesson11.txt");
if(!file.open(QIODevice::WriteOnly)) {
    QMessageBox::information(0,"error",file.errorString());
}
QString dd;

for(int row=0; row < model->rowCount(); row++) {
     dd = model->item(row,0)->text() +  ","
                 + model->item(row,1)->text() +  ","
                 + model->item(row,2)->text();

     QTextStream out(&file);
     out << dd << endl;
 }
Run Code Online (Sandbox Code Playgroud)

但是我没有成功再次阅读同一个文件,我尝试了这段代码,但我不知道它的问题在哪里

QFile file("/home/hamad/lesson11.txt");
QTextStream in(&file);
QString line = in.readLine();
while(!in.atEnd()) {

    QStringList  fields = line.split(",");

    model->appendRow(fields);

}
Run Code Online (Sandbox Code Playgroud)

有什么帮助吗?

qt

24
推荐指数
1
解决办法
14万
查看次数

如何以编程方式创建DrawerLayout

我想在我的主要活动中将这个xml翻译成java,输出是导航抽屉.我只需要帮助这一部分,我完成了剩下的部分.

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<FrameLayout
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</FrameLayout>

<ListView
    android:id="@+id/drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#FFF"
    android:choiceMode="singleChoice"/>
Run Code Online (Sandbox Code Playgroud)

我想在java代码中写上面的xml,怎么样?

提前致谢

更新

final DrawerLayout drawer = new android.support.v4.widget.DrawerLayout(this);
     final FrameLayout fl = new FrameLayout(this);
     fl.setId(CONTENT_VIEW_ID);
     final ListView navList = new ListView (this);

     drawer.addView(fl, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
     drawer.addView(navList);

     setContentView(drawer);
Run Code Online (Sandbox Code Playgroud)

我需要一些帮助来在代码中自定义listview的布局宽度和布局重力.

android listview drawerlayout

6
推荐指数
1
解决办法
7604
查看次数

标签 统计

android ×1

drawerlayout ×1

listview ×1

qt ×1